-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Generating static sites on-demand with Nuxt.js #2370
Comments
Could you explain your use-case a bit more? How many pages / routes are you talking about? What do you use the isGenerating flag for? Why is everything in ./dist a problem? In my experience its not really useful to use payloads when generating 1.000's of pages. The required memory overhead is too much compared to the overhead of an additional axios request in async-data and generating 1000's of payloads at once just takes too long. Its better to spread the load on the server a bit by just using requests from async-data. Probably this is directly related to the complexity and speed of your payload contents, api and/or api server My use-case is as follows: I have a website with say ~12.000 product pages. The backend runs on two servers, one for the api and one for nuxt. Both servers are identical in specs, in my case generating a page with nuxt takes more or less the same time as generating the product data so I can use this 1:1 ratio. The ratio you need will probably differ, depending on the complexity of your nuxt pages and api My website is not hosted on S3, I just have a small lightweight vps. So not sure whether my use-case is helpful for you but after nuxt-generate-cluster has finished I run a script that checks if the chunkhash has changed, if it wasnt I directly rsync to the remote pub folder on the vps (as rsync is atomic). If the chunkhash was changed I rsync to a tmp pub folder on my vps and use a mv command to replace the old pub folder with the new one. If you want to 'stream directly to S3' after a page has generated you would need to copy the Hope this helps. |
This is incredibly helpful, thanks.
It's quite a different setup to you in that I'm building a site builder. The output being a single page or multi-page site constructed on the fly from the inbound API payload. The output in The setup I have is a single Nuxt page that I'd like as a catch-all for all inbound routes. As the routes are defined and data needed to render the page is provided to Can I have a single Nuxt page as a catch-all to render all incoming routes?
I would imagine anywhere from 1 - 10 pages per site.
It may be a little clearer now why I have the isGenerating flag as I'm unable to have multiple nuxt-generate's running in the same output dir as I need to package up the output and upload to S3 automatically. Hopefully that's a little clearer as to what I'm trying to do @pimlie ? |
You can use the |
Interesting. If I update in the nuxt.config.js then the output changes, however setting |
Hmm yeah, internally the generator uses |
Ahh thanks. Now I'm creating a new Builder & Generator instance with each site request, they end up in different directories (as specified in the distPath) but now I have context issues - they're all the same content. If I try to generate 3 different pages in parallel (I'm using a simple bash script with 3 Is this a Nuxt generate() concurrency issue, or my code? I'm guessing a test repo is needed, I'll see if I can pull together tomorrow. |
I've created a reduced test-case that demonstrates the issue here: Any help would be gratefully received. |
A colleague just pointed out that the require on the nuxt.config.js is a single reference. I changed the nuxt.config.js to return a function & all good! Have updated the repo for reference. Thanks for the pointers @pimlie |
I did some research on the subject as well and stumbled over your posts @pimlie , this one and this. We have to solve a similar challenge at the moment and I am trying to generate up to 50k product pages from a product catalog as static pages. We want to fetch the data from a headless CMS and pass it to Nuxt which should generate the pages. It is not a shop, so no complexity in this regards. You already described your approach quite well in the post above, I can't follow it trough completely though, but before I put more effort in this I wanted to ask you... What is your conclusion and would you do it again in a similar way?
I really appreaciate a few words from you about your experience about this, now some time after you implemented it. Cheers and thank you! 🙏 |
@jameswragg payload may still be useful if instead of loading all of the data in there upfront you make the payload a function. |
Or what you could do is implement an iterative approach. Eg make sure that your routes api endpoint returns not only returns routes of changed products but also all the related pages which where (possibly) influenced by that. Then after the first iteration you request all the routes that where (possibly) changed since nuxt-generate-cluster last started and keep doing that until routes returns 0 routes. In my setup this is not really an issue, my product pages dont refer to each other. So its mostly category pages referring to product pages and if one product changes I just re-generate that page and all the category pages (eg cat A page 1, cat A page 2 etc). In other words, I dont bother actually with generating the pages as a single transaction. My data changes all the time, so I just generate the pages every 1 or 2 hours and accept that my data can be stale for max 2 hours. Thinking about it, you could pre-load all the payload data, save it to disk and then implement a payload method like qm3ster suggested which returns the payload data from disk. This would solve your single transaction issue, but I found that (at least in my situation) this wouldnt give any performance benefit due to my api being quite heavy and it was better to just spread the load evenly over time. I have been looking into a project to implement a push strategy for generating pages (nuxt-generate-cluster pulls from the api, this project should accept pushes from the api). That way you could implement a real continuous deployment with static files which are generated on demand. Every time your product data changes a new page for that product should be automatically generated at the same time. But this project will probably take a while to implement and mature... @qm3ster But is there really a performance benefit to that approach (from the nuxt point of view)? Whats the difference of calling a payload method with regards to asyncData? |
Sorry, that should be @peckomingo :) |
@pimlie the purpose of the payload api assumes that you can get a bunch of data all at the same time. module.exports = {
generate: {
async routes() {
const [
seeds,
sharedData
] = await Promise.all([
getSeeds(),
getSharedData()
])
return seeds.map(seed => ({
route: '/bepis/' + seed,
payload: {
data: sharedData[seed],
backdoor: () => backdoorFunction(seed)
}
}))
}
}
} |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi, I'm trying to create a static-site on-demand API using hapi.js to power the API & nuxt.js as the static-site generator but hitting some blockers….
Here's my setup:
generate.routes
array (passing payloads in for each route)generate()
to create the static site in./dist
Issue:
This API is potentially going to be hammered - building a lot of individual content pages and pushing them to S3 buckets. All generated sites going to the
./dist
directory is a problem - I currently have anisGenerating
flag to prevent multiple generate calls, forcing the client to re-try the API.Thanks in advance,
James
The text was updated successfully, but these errors were encountered: