Having a serious problem with clients’ browsers showing them cached copies of old css files so they don’t see the updated design, and them telling me it is a nightmare to try to empty their cache (on phones mostly nowadays), and not being happy. So what is the best way to force the visitor’s browser to fetch an updated copy of the css file without manually changing the name of the css file?
Found the LastModified package, installed it, but the snippet call below does nothing (no css file is found and returned, so the page is displayed unstyled):
Capitalising the L does not make it work. The css file is in place at css/main.css. The result is:
<link rel="stylesheet" type="text/css" href="">
The idea behind the package seemed perfect. Is it a good solution? If so, how to get it to work? (The documentation gives zero instruction on the correct snippet call.)
Now, any time you want to force an update to the group of files you added the ?ver=[[!++_version]] to … just change the _version number in your new System Setting.
I’ve been doing it this way for years and it works well for me.
Only downside might be that if you’ve got several files set up to get forced updates, but you’ve only changed one of them, it’ll still force the update to all of them. Not the end of the world IMHO unless you’re updating stuff constantly.
That seems to my uneducated and aching brain to be a good solution. You need to manually update the version number each time, whereas the LastModified solution seemed to promise an automation of that. Have you tried the LastModified snippet/package? And do you know if MinifyX is irrelevant (because it doesn’t alter the style filename after update)?
Neat. If I understand that, the cache at the visitor’s end is busted every time the page is loaded or every time MODX chooses to refresh its own cache. Perhaps that’s more busting than is really needed.
Provisionally, going to go with dejaya’s suggestion, relying on a single manual update of a system setting whenever clients with caches appear on the horizon, keeping the busting to a minimum.
The cache will be busted every time the file is modified. It’s just called uncached to allow it to check the file modified time on each page load. The parse time for this snippet is about 0.0034781 seconds, so doesn’t really affect page load times.
The Modx Manager uses a similar function to check a files last modified time.
If it doesn’t already exist, it would help if there were a page in the MODX documentation somewhere summing up what the hive mind has decided is the best solution to this problem. Wordpress seems to have a version numerating system out of the box, and it would be nice to at least see some semi-official statement of what the MODX equivalent is. Or maybe it is there and I just couldn’t find it.
It seems to me that lastModified might be overkill if all you want to do is bust the cache by changing the query part of the URL, since it has a number of options and properties that it parses on every execution.
There are two Extras, called lastModified.
One is a simple snippet, which the OP is talking about.
The other one is a more complex plugin. Not sure what that one really does.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.