When a sanitation worker is insulted by the owner of a fancy car, what will people do?
What problems might arise if the HTML page links to pre-compressed
script_v1.gz.js (instead of without
gz) when the application sees
gzip in the
Accept-Encoding request headers?
And do I need to set any special headers on these files in S3? (other than the obvious Content-Encoding: gzip)
Why do you want to serve those static assets with a
gz extension at all?
Despite being the common indicator for ages, file extensions are actually an inferior and inaccurate mechanism to communicate a MIME type in the first place: ideally, web resources should be entirely agnostic to file extensions and only communicate their content by means of appropriate HTTP headers like
Content-Encoding (which by the way eases maintaining an URI space as well - Cool URIs don't change ;)
Granted, this has not worked in the early days of the internet, and might still not work with a few inferior clients (annoyingly some proxies and weaker mobiles seem to suffer from this still), but unless you can clearly identify a relevant portion of your audience being affected from this limitation (and nudging them to upgrade their browser eventually is not an option), you should probably start to simply trust the HTTP headers in use instead.
Consequently I'd simply serve the static assets pre-compressed with the
Content-Encoding and (to address your last question) the equally important
Content-Type headers (else clients would indeed need to infer the media type from the extension and/or the content itself), but without the
Obviously, once you rely on
Content-Encoding, this should work just as well, if you'd serve it with
gz.css (or no extension at all for that matter), however, as outlined above, this might actually turn out to be misleading to downstream clients, insofar they do not not necessarily have to deal with an gzip encoded file anymore (a proxy might have decoded it already for example).
- So there is no way to do this directly with S3, just with CloudFront?
- @Evgeny: No, you can set all required headers with S3 just fine (see e.g. section Request Headers in PUT Object); the referenced sample simply happens to address a use case with CloudFront using a S3 origin server.