Returning users getting stale content after Cache Purge

caching

#1

I recently performed general site upgrade and moved servers. However, many (or all?) return visitors are getting a mix of new and stale content. This is causing various Javascript and rendering errors. The site in question is a Magento 2 installation, and I have cleared its cache, I’ve flushed the redis cache, and purged my Cloudflare cache, yet even I still get old content.

If I open an “incognito” window and visit the site, I get all fresh content and the site works as intended. Alternatively, I can open the browser’s developer tools and choose “disable cache”. Clearing browser cache seems to have inconsistent results.

For reference, are the response headers of a javascript file that I have identified as stale:

HTTP/2.0 200 OK
date: Mon, 12 Mar 2018 12:44:35 GMT
content-type: application/javascript
last-modified: Wed, 10 Jan 2018 12:40:28 GMT
etag: W/"[alphanumerics and dashes]"
vary: Accept-Encoding
cache-control: public, max-age=31536000
expires: Tue, 12 Mar 2019 12:44:35 GMT
x-frame-options: SAMEORIGIN
cf-cache-status: HIT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: [alphanumerics]-EWR
content-encoding: br
X-Firefox-Spdy: h2

And here are response headers for the same file when loaded from an incognito window:

HTTP/2.0 200 OK
date: Wed, 11 Apr 2018 18:53:54 GMT
content-type: application/javascript
last-modified: Sat, 31 Mar 2018 00:01:57 GMT
etag: W/"[alphanumerics and dashes]-gzip"
vary: Accept-Encoding
cache-control: max-age=31536000, public
expires: Thu, 11 Apr 2019 18:38:09 GMT
x-frame-options: SAMEORIGIN
cf-cache-status: HIT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: [alphanumerics]-EWR
content-encoding: br
X-Firefox-Spdy: h2

#2

date: Mon, 12 Mar 2018 12:44:35 GMT

That’s the date the request for the asset was made for the client I believe, so I would try purging the cache again. If the client cache TTL says the item isn’t expired it won’t request a new version from the origin.


#3

And the max age is set to 365 days for that object.

cache-control: public, max-age=31536000


#4

As a workaround you might be able to use versioning file.js?v2 to force the client to request the new asset(s).


#5

Thanks for the hint! Turns out Magento has a hidden setting to “sign” static files, so that when new versions of JS and similar are deployed, it creates a randomly generated folder so that the static files get a new URL. By enabling the “sign static files” feature, all of static files were given a new URL and that seems to have solved my problem.

Thanks!


#6

Thanks for the tip, hopefully it will prove useful to other Magento users!


#7

This topic was automatically closed after 14 days. New replies are no longer allowed.