Improve cache handling of data.json files
See original GitHub issue🧩 Feature request
Description
Depending on server config data.json
files are cached sometimes. I know we can opt out from using them in favor of index.html
files, but to have the highest performance I believe data.json
is the best way.
It would be great if Scully provided a mechanism which would make these files work with cache.
Describe the solution you’d like
The most straightforward thing to do in my opinion is this:
- In
puppeteerRenderPlugin
add something likewindow['ScullyIOGenerationTime']=${Date.now()}
- In
TransferStateService
inng-lib
loaddata.json
like so:
`/data.json?gen=${ScullyIOGenerationTime}`
This will not only prevent unwanted cache, but will also work fine with being cached in between generations giving even better experience to the user. If there are any drawbacks to this, it can be further improved I believe. But if the proposed solution is good, then I can open a PR.
Describe alternatives you’ve considered
Alternatively I can write a custom plugin in my project to that generation timestamp to my pages and then reprovide patched version of TransferStateService
in my project. But it would be much better to solve this on Scully level.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top GitHub Comments
This is a good feature request, and we will put it on our list. Don’t expect a solution within a few weeks, but we will land one.
@yringler I would accept a PR for this. The main problem is how to get the hash back into angular.
The way described has a flaw. We support partial rendering. That means, that your data.json might be generated in multiple sessions/ Scully runs. A solution would have to cater for that. We do have incremental builds in the future, and those can not be hampered by supporting this feature.
Keeping an index would be a possibility, but if you are generating more than a few thousand pages, this might not be a good solution. I did think about this before, but the solution isn’t obvious.