mod_pagespeed auto-versioning?

126 views
Skip to first unread message

Mac Black

unread,
Nov 6, 2019, 5:55:04 AM11/6/19
to mod-pagespeed-discuss
I'm developing my site continuously and so my css and js can change on a daily basis. But since incorporating mod_pagespeed on my (Plesk/Apache + Ngnix) web server each time I make a change (despite a hard refresh in Chrome) the only way to reflect new changes is to purge the cache.

I read somewhere that mod_pagespeed include auto-versioning but after a bit of testing I see this isn't the case.

So is there an option to switch it on or can you recommend a "best practice" for auto-versioning?

Thanks in advance

Mac

Joshua Marantz

unread,
Nov 6, 2019, 6:14:49 AM11/6/19
to mod-pagespeed-discuss
What is the cache TTL of your origin css?

In the absence of mod_pagespeed, how quickly would you expect a change in your css to become visible to users? Note that users have browser caches, and are behind ISPs that may have proxy caches.

My guess is you should probably set your cache TTL between ten minutes and an hour, which means it will take an hour to propagate your changes.

But also, you are aware that you can selectively purge the cache of just the specific css file you are changing to get instant updated, right? That might be a good way to go, rather than purging the entire cache.

--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/971cecf7-ecb8-41ba-8d32-5ae8ffd990a8%40googlegroups.com.

Longinos

unread,
Nov 6, 2019, 6:23:24 AM11/6/19
to mod-pagespeed-discuss
Hi Mac

Optimized resources, such is js and css files, have in their file name some like file-name.css.pagespeed.xx.HASH.css.
where the xx is the type of optimization ( ce is cache extended, jm javascript optimization....) and the HASH is a hashed chain that changes when the file conten changes.

That´s the way pagespeed make optimized resources don´t care about caching it cause if the file content changes, the hash changes.

Maybe you are facing an issue with an intermediate cache? or have su set pagespeed to don´t change the url?

Mac Black

unread,
Nov 6, 2019, 7:18:34 AM11/6/19
to mod-pagespeed-discuss
I don't know what TTL is, a quick google tells me its Time to Live but I don't know if I'm missing this or its a default I need to change?

Yes I did know you can purge the cache for an individual file, but as I'm making quite a few changes, I just cleared the whole cache, I suppose this is bad practice I need to resole.

On Wednesday, 6 November 2019 11:14:49 UTC, jmarantz wrote:
What is the cache TTL of your origin css?

In the absence of mod_pagespeed, how quickly would you expect a change in your css to become visible to users? Note that users have browser caches, and are behind ISPs that may have proxy caches.

My guess is you should probably set your cache TTL between ten minutes and an hour, which means it will take an hour to propagate your changes.

But also, you are aware that you can selectively purge the cache of just the specific css file you are changing to get instant updated, right? That might be a good way to go, rather than purging the entire cache.

On Wed, Nov 6, 2019, 5:55 AM Mac Black <mccoll...@gmail.com> wrote:
I'm developing my site continuously and so my css and js can change on a daily basis. But since incorporating mod_pagespeed on my (Plesk/Apache + Ngnix) web server each time I make a change (despite a hard refresh in Chrome) the only way to reflect new changes is to purge the cache.

I read somewhere that mod_pagespeed include auto-versioning but after a bit of testing I see this isn't the case.

So is there an option to switch it on or can you recommend a "best practice" for auto-versioning?

Thanks in advance

Mac

--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-discuss+unsub...@googlegroups.com.

Mac Black

unread,
Nov 6, 2019, 7:21:16 AM11/6/19
to mod-pagespeed-discuss
The file I'm changing at the moment is called style.css, I see pagespeed has rewritten this to A.style.css.pagespeed.cf.H0NnE0Szk0.css. However when I change the contents of the file on dev and transfer to live and do a hard refresh in Chrome, there is no change to this file.

Mac Black

unread,
Nov 6, 2019, 7:37:17 AM11/6/19
to mod-pagespeed-discuss
OK I think I get it, its the caching policy of the server, in my case Apache. When I set this up I followed some "best practice" guidelines and so CSS files are set to 1 week. So If I understand it that means the css file will expire in a week and the browser will request a "fresh" copy. Without any versioning and pagespeed, it will take a week for changes to be seen (in this example).

But I thought that with pagespeed it identifies a change in the file and creates a new file with the hash suffix, as the browser will not have this file, it will download it, therefore changes are instantly reflected?

Shane Marsh

unread,
Nov 6, 2019, 7:54:32 AM11/6/19
to mod-pagespeed-discuss
I found the best way to get around this issue is to append a version number to all enqueued CSS and JS files. Something you can easily update:

<link rel="stylesheet" type="text/css" href="mystyle.css?ver=1.0.0.1">

Then all you need to do is increment the version number. We programmically do this within wordpress using a unix timestamp but essentially it allows you to have long expiries (I have 365 days set on our systems) but when you update the version number, pagespeed and browsers will treat it as a new file and the changes take effect immediately. 

Shane :)

Otto van der Schaaf

unread,
Nov 6, 2019, 8:03:18 AM11/6/19
to mod-pagesp...@googlegroups.com
PageSpeed acts a bit like an intermediary http cache, and respects the caching directives it sees. so if a response says it's valid for a week,
the module will only re-check after that period. Having said that:

- You could try LoadFromFile, which will make changes propagate through PageSpeed instantly.
- I think you could also serve the css with a shorter cache ttl (e.g. one hour), and rely on the extend_cache filter to apply effective browser caching.


To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/db9362a4-b877-4b7a-aba7-013564094c8f%40googlegroups.com.

Mac Black

unread,
Nov 6, 2019, 8:06:56 AM11/6/19
to mod-pagespeed-discuss
Thanks Shane, I have seen that approach and I'll bear that in mind, but the more reading I do I get the impression pagespeed will do this for you. Here's the paragraph from https://www.modpagespeed.com/doc/filter-cache-extend 

The 'Extend Cache' filter rewrites the URL references in the HTML page to include a hash of the resource content (if rewrite_css is enabled then image URLs in CSS will also be rewritten). Thus if the site owners change the resource content, then the URL for the rewritten resource will also change. The old content in the user's browser cache will not be referenced again, because it will not match the new name.

What I'm struggling with however, is how to "tell" pagespeed to look for a new version, its linked to what jmarantz says above with TTL but I don't know how to set this? I believe this to be different to your browser caching on the web server which ideally you want to set for as long as possible.

Shane Marsh

unread,
Nov 6, 2019, 8:13:13 AM11/6/19
to mod-pagespeed-discuss, mod-pagespeed-discuss

I think if you need pagespeed to know when to update a file in it's cache automatically and without having to manually purge, as Otto suggests, LoadFromFile is the way forward.



Shane Marsh | Technical Manager




---- On Wed, 06 Nov 2019 13:06:56 +0000 Mac Black <mccoll...@gmail.com> wrote ----

--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.

Joshua Marantz

unread,
Nov 6, 2019, 8:13:23 AM11/6/19
to mod-pagespeed-discuss
Yeah one of the values of PageSpeed is to do the auto-versioning for you but you need to get the caching right up front.

Best practice for CSS files is a week if you don't have PageSpeed. If you have PageSpeed (and can't use LoadFromFile), try between 10 and 60 minutes. PageSpeed will serve a versioned file with a 1-year expiration and update the version every 10 minutes or an hour.

I wrote this much more clearly a long time ago when I wrote this: https://www.modpagespeed.com/doc/filter-cache-extend -- please give that a look :)  That caching functionality is also built into the css and js minification filters. 

--

Longinos

unread,
Nov 6, 2019, 8:43:22 AM11/6/19
to mod-pagespeed-discuss
Hi Mac

Put some like this in your .htaccess or in your virtual host config section:

<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=600, public"
</filesMatch>
 
for a 10 min. caching policy. This make pagespeed to check the file each 10 min.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-discuss+unsub...@googlegroups.com.

Mac Black

unread,
Nov 6, 2019, 8:58:03 AM11/6/19
to mod-pagespeed-discuss
Thank you jmarantz, this is the answer I was looking for! What I missed was the link between the web server caching and how this influenced PageSpeed, you've answered that perfectly.

To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages