Using one payload.js file for all Nuxt static generated routes with identical data

I am facing a challenge with my NuxtJS site where I have only one page /pages/matrix/index.vue but numerous dynamic routes pointing to this page, all utilizing the same data set. During static build generation for deployment on Netlify, the size of the dist folder has ballooned to approximately 1.2 GB, comprising:

  • 3125 .html files in dist/matrix (taking up around 39% of the space)
  • 3125 folders containing payload.js files in
    dist/_nuxt/static/[random]/matrix/
    , each within subfolders for specific routes (occupying approximately 61% of the space)

This colossal chunk of 61% consists of 3125 duplicates of a 220kB payload.js file that hold identical data: [{}], with only the route differing:

__NUXT_JSONP__("/matrix/place2/time3,time14,time29", (function(a, b, ...) {
    return {
        data: [{ /* data does not change */ }],
        fetch: {},
        mutations: void 0
    }
}("nor", "does", "this")));

I am exploring ways to minimize this redundancy by potentially extracting the common data section. The possibility of reducing ~665 MB down to just 220kB is quite enticing.

Additional Context:

The routes vary from /matrix, /matrix/place1 to

/matrix/place8/time1,time7,time18
. When generating the site, I retrieve all the necessary data from a headless CMS and pass it to my page component using the payload option. Initially, I utilized File System Routing and imported the pages/matrix/index.vue as follows:

// pages/matrix/_places/index.vue
<script>
  import Index from '../index'
  export default Index
</script>

This approach seemed flawed yet functional. I attributed the excessive payload files to this method (albeit without fully grasping the intricacies of static generation). Subsequently, I transitioned to extendRoutes leveraging the following setting in my nuxt.config.js:

router: {
  extendRoutes (routes, resolve) {
    routes.push(
      {
        name: 'matrix-place-times',
        path: '/matrix/:place/:times',
        component: resolve(__dirname, 'pages/matrix/index.vue')
      },
      {
        name: 'matrix-place',
        path: '/matrix/:place',
        component: resolve(__dirname, 'pages/matrix/index.vue')
      }
    )
  }
}

Unfortunately, the number of payload files scattered across route-specific directories remains unchanged.
Any suggestions or guidance on this matter? Operating on Nuxt v2.15.7.

Answer №1

Here are a few thoughts I have:

  • Implementing SSR could potentially resolve some of the issues you're facing (even though you mentioned sticking with Netlify)
  • Consider using aliased routes, particularly if you have identical data available at different endpoints
  • This video provides insights on ISG and other methods for better handling large volumes of pages
  • Nuxt3 has the capability to operate on Cloudflare workers, offering a unique middle ground solution that isn't quite SSR or ISG but can effectively render pages at a reasonable cost and speed

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

One issue with AngularJs is that it does not accurately display data that has been modified within

My MediaService service is being modified within a component. The data in MediaService is connected to another component, but any changes made in the first component are not reflected in the HTML of the second component. MediaService angular .module(&apo ...

"jquery-ajax was unable to complete the request, whereas it was successfully executed using

I am currently using jQuery to trigger an ajax request. However, when I make the request using jQuery, I encounter an "Unexpected end of input" error with no response coming from the PHP file. Strangely enough, if I manually copy the request from the Chrom ...

Moving Configuration Files in NextJS

When working on a typical Next.js project, I often end up with several root-level configuration files: tsconfig.json next.config.js next-seo-config.ts .eslintrc etc... I am looking to tidy up my root directory by moving these files into their own separat ...

Is it better to utilize AngularJS $http service for making requests, or should I opt for jQuery AJAX if available

When working on my project, I rely on the angularjs framework and always enjoy utilizing the $http service for ajax calls. However, I have come across situations in the project where the UI is not directly impacted by the ajax call and angularjs bindings a ...

Quick method for handling arrays to generate waveforms

I'm currently working on optimizing the code for my web application. While it functions, the performance is a bit slow and I am looking to make improvements: The main concepts behind the code are: The function retrieves the current buffer and conve ...

What is the proper way to select this checkbox using Capybara in Ruby?

Is there a way to successfully check this checkbox?view image description I attempted the following: within('div[id="modalPersistEtapa"]') do element = @driver.find_element(:xpath, '//*[@id="2018_4"]/ ...

Place attribute value directly under the border of an HTML element using a combination of JavaScript and CSS

I'm currently working on a JavaScript script to scan the DOM for elements that have a specific custom attribute called example-type. The goal is to apply CSS styling to draw a border around these elements and then display the value of the example-type ...

Adjust the appearance of input fields that exclusively have the value "1"

When designing my website, I encountered a problem with the style I chose where the number "1" looks like a large "I" or a small "L." I am wondering if there is a way to use JavaScript to dynamically change the font style for input fields that only contai ...

Sending JSON data parsed by oboe.js to the http response object in a Node.js server

Using Oboe.js for JSON parsing from a Node readStream with the aim of sending it back to the requesting client in a memory-efficient manner. I'm exploring the possibility of piping data from Oboe's node or path events to a Node.js HTTP response o ...

Building custom directives on AngularJS pages without a specified ng-app module

On some of my basic pages, I don't need to specify a particular application module in the ng-app attribute. However, these pages do utilize some custom directives that I have created. To keep things organized, I have placed all of my directives withi ...

Sending data using jQuery when a button is clicked

Is there a way to display the text from a text box when a button is clicked? Here's what I have been attempting: <script type="text/javascript> $(function() { $('#button').click(function(){ $.ajax({ type: "PO ...

Evolution of Vue's v-for feature from version 1 to version 2

Currently, I am in the process of learning Vue.js and stumbled upon a fantastic fiddle that perfectly showcases what I want to achieve. To view the fiddle yourself, click here: https://jsfiddle.net/os7hp1cy/48/ After integrating this fiddle into my proje ...

The Safari browser is currently having trouble loading the data sent back from the server

After successfully developing and deploying my website carspeedyrental.com, I received reports from some clients indicating that the website does not display available cars on the iPhone Safari browser. Interestingly, when tested on various browsers on A ...

What is the method for setting a condition within the setState function?

I used if for the title: in SetConfirmDialog, but it's not working. How can I fix this? <Button color={user.active ? "success" : "error"} variant="text" startIcon={<UserCheck />} title={user.active ? &quo ...

Accessing the selected list item from an unordered list in Vue.js

How can I capture the selected item from a dropdown-style list and perform operations based on that selection? In my list, each item is associated with a key for unique identification, except for 'Create New Filter'. I am seeking guidance on ho ...

Having trouble with importing SendInBlue into my NodeJS application?

Currently in the process of updating my Node app to utilize ES6 import modules over requiring files. Encountering difficulties while trying to integrate this change with SendInBlue for email functionality, resulting in the following error message: TypeEr ...

Running pug directly from the local node_modules directory

I'm currently attempting to run pug (/jade) from my node_modules directory, however I am unable to locate the executable within the node_modules/.bin folder. I am running MacOS 10.12.5 and installed pug using the "npm install --save pug" command. Is ...

Having difficulty invoking a JavaScript function at a global level

Currently, I am working on a nodejs application that involves mongoDB integration. In my code, I have created a function to extract specific data from MongoDB and save it in a variable called "docs". Despite multiple attempts to declare the function global ...

Utilizing JavaScript to conceal div elements within a ul container

How can I hide specific div tags inside a ul tag using JavaScript? All div tags are currently getting hidden when I use the id of the ul tag. However, I need only the first div tag to be shown and the rest to be hidden. Here is the HTML code: <ul clas ...

Does anyone have any sample code on processing JSON data from a URL using Modified JavaScript Value in Java?

Could anyone provide some examples on how to handle returned Json data using Modified JavaScript Value? Here is the specific data I require from the json url: { "result": { "data": [ { "name": "page1", "period": "dia", "values": [ { "value": 4, "end_time" ...