pkp / pkp-lib

The library used by PKP's applications OJS, OMP and OPS, open source software for scholarly publishing.
https://pkp.sfu.ca
GNU General Public License v3.0
299 stars 444 forks source link

Support cache busting when theme assets are updated #4841

Open NateWr opened 5 years ago

NateWr commented 5 years ago

Describe the problem you would like to solve When a custom theme is updated (not through the plugin gallery), the browser's cache is not busted so CSS and JavaScript assets won't update immediately.

Also, the theme's version that is stored in the database does not get updated automatically when the version.xml is changed, so it's not possible to add the theme version to the URL request as was done with #3340.

Describe the solution you'd like When a theme's version is updated the version in the database should change, regardless of how the theme was updated.

Who is asking for this feature? Anyone who builds a custom theme.

Additional information Original report and details here: https://github.com/pkp/pkp-lib/issues/3340#issuecomment-504755341

NateWr commented 5 years ago

An alternative solution to consider: it would be great if we linked directly to the compiled CSS asset for themes, rather than the PHP compiler. I think we'll get some performance improvements on the frontend since that extra request won't need to bootstrap the application.

Perhaps an approach would be to check whether the file exists and, if it doesn't, compile it before the HTML is sent back to the browser.

With this approach, we could bake a timestamp into the filename and we'd get the best of both worlds: a static asset with a unique URL.

NateWr commented 5 years ago

Apparently there is a CLI tool to update the version in the database: lib/pkp/tools/installPluginVersion.php. (From https://github.com/pkp/pkp-lib/issues/3340#issuecomment-505026431).

NateWr commented 5 years ago

From @edyrhaug (source):

What do you guys think - can we go ahead with this then? It seems my proposed changes will work nicely after all? Theme developers just have to know about the installPluginVersion script if they want to update locally or through git, while it would work automatically for people who update the theme they are using by uploading a new version through the web ui?

My main concern is that the theme version is added to every asset, even if it's not the theme's. It also doesn't solve the problem when a parent theme is updated but the child theme is not.

If a theme version is appended to the query string, I'd like to see it done in ThemePlugin::addStyle(), and it should append the version of the theme that is actually adding the style.

(It would also probably be about the same amount of work and more robust to implement the alternate solution).