10

So, I want to add versioning to my css and js files. The way I would like to do this is by appending a query string to the end of the asset path so

/foo/bar/baz.css

Becomes

/foo/bar/baz.css?version=1

This will work for proxies and browser cache, however, I was wondering if Akamai will know this is a new file and re-request it from the origin server? My assumption would be that it would re-request the file from the origin server but figured I'd ask if anyone knew for sure.

JoeyP
  • 2,622
  • 2
  • 26
  • 25

3 Answers3

4

Not quite. It depends on the CDN configuration. Query String values are usually not part of the cache-key. So, when setting up the CDN delivery config, make sure you explicitly add the option to include the Query String as part of the cache-key. Otherwise, you will end up serving inconsistent versions due to having a cache key that does not vary based on the query string value, in this case, the asset version.

MikeBoss
  • 375
  • 1
  • 9
  • I'm looking for a reference for what is "usually" part of the query string for CDNs. There seem to be no rules. I noticed that browser caches always considers the whole URL (excluding fragment) in the request as a strict standard, but CDNs in general seem to not. – Phil Apr 04 '18 at 13:29
4

Yes. It matches exact URLs for all GET requests.

jiggy
  • 3,828
  • 1
  • 25
  • 40
  • 2
    As an interesting aside, a recent [paper](http://vorlon.case.edu/~misha/otherPubs/cdn_attack.pdf) (see also: [article in IEEE Spectrum](http://spectrum.ieee.org/telecom/internet/network-defense-gone-wrong/0)) showed that many CDN's default handling of query strings can be used for DOS attacks against origin servers. – Josh Rosen Mar 23 '11 at 20:51
0

I prefer to have a url like '/css/DEVELOPER_BASE/foo/baz/style.css'.

Your build/deploy scripts do a global find and replace on '/css/DEVELOPER_BASE/' with '/css/[version_number]/'

To make this work you then have two options.

  1. Your deploy script copies the css files from '/css/DEVELOPER_BASE/' to '/css/[version_number]/'
  2. Your web server does an alias (not redirect) for '/css/[version_number]/' to '/css/DEVELOPER_BASE/'

This will keep you from having to worry about how browsers and CDN's handle query parameters.

Angus
  • 128
  • 2
  • 9