nystudio107 / craft-vite

Allows the use of the Vite.js next generation frontend tooling with Craft CMS
MIT License
52 stars 16 forks source link

How to use with Blitz #85

Closed francoislevesque closed 7 months ago

francoislevesque commented 7 months ago

Question

We are currently using Blitz to cache websites. Vite uses a versioning system each time JS and CSS files are compiled. This causes a issue with Blitz, since it caches whole HTML pages. After every deployment, we get 404 errors on JS and CSS files.

How you would suggest fixing this issue without downtime?

The easy solution would be to delete and generate all cache, but this is resource intensive, especially when we perform many updates.

Using the vite config, is there another solution ?

Thank you!

khalwat commented 7 months ago

The typical solution is to do as you said, delete the caches and regenerate them.

You're changing the file name of the files you're serving up, to ensure that browsers download the newly updated versions, but the file name is hard-coded in the statically cached HTML.

For this to work without having to regenerate the static cached HTML, you'd need to point it to a JavaScript file whose name never changes in your static HTML, that then would read the manifest, and serve up the new version.

You could probably do this either in all JavaScript or in a combination of PHP and JavaScript, but that's probably overcomplicating things, and only really viable in a very high traffic site.

bencroker commented 7 months ago

Note that if you use cached includes to include your resources, then you can clear/refresh only those includes on deployment, rather than the entire cache.

php craft blitz/cache/refresh-urls http://domain.com/_includes...