DreaMinder / nuxt-payload-extractor

Nuxt.js module that makes `nuxt generate` command to store html and payload separately.
MIT License
145 stars 18 forks source link

idea: single payload.js to fetch unique payloads #11

Open kentkravitz opened 5 years ago

kentkravitz commented 5 years ago

Hey, I'm wondering if this is possible and if there would be any downsides?

Currently, there is a payload.js and payload.json generated for each page. They both contain the same data but in different formats.

Would it be possible to have a global payload.js that simply grabs the payload.json file per page? That way the .json would work as usual and payload.js could be cached and only need to be downloaded once. It would cut down on the number of files generated as well.

DreaMinder commented 5 years ago

Hey @kiwimonk. That's interesting, but it might work for small range of use-cases. Because payload-json has only data related to a specific route, and payload.js has data for the whole page (which may contain multiple routes at the same time). If page implemented with nested-routes, one payload.js consists of multiple payload.json. Also, payload.js has vuex store data and some flags...

Not sure if it is worth it so far.

kentkravitz commented 4 years ago

Hm that gives me an idea. I wonder if it's possible to then instead fetch the payload.js file and parse the correct portions? I'll play around with my code and see if I can get it going. I simply don't like the idea of duplication and I'm planning on having a decent amount of data on each page.

Thank you

DreaMinder commented 4 years ago

@kiwimonk there is actually no duplication from the user point of view. A user wouldn't have to download two same data-payloads during his workflow. Payload.js is only for initial page load and payload.json is for client-side navigation. Payload.js will need to be downloaded only once per session...