pubnub/pubnub-api — Issue #54: configure expires header on CDN
Author: jjb
Created: 2011-12-09 04:25:53+00:00
State: open

The expires header is set to the year 2000, so the browser always has to ask cloudfront again if the file has changed. It does use the file from cache, but it has to do a roundtrip to cloudfront and get a 304 first. Here's how the header is now:

➔ curl --head http://cdn.pubnub.com/pubnub-3.1.min.js
HTTP/1.0 200 OK
x-amz-id-2: tgbRtfZzl+B0wBmXFyKnbjbznMeYezHPjle4dxkk60oB/pa4+lNGy6Qhuhz2QcZy
x-amz-request-id: A58E1C664EDA7924
Date: Thu, 17 Nov 2011 23:49:57 GMT
Content-Encoding: gzip
Expires: Wed, 01 Jan 2000 16:00:00 GMT
Last-Modified: Thu, 17 Nov 2011 23:17:22 GMT
ETag: "4106efb70c304c6efe70d6a51ec9527a"
Accept-Ranges: bytes
Content-Type: text/javascript
Content-Length: 3374
Server: AmazonS3
Age: 68624
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: 3a37c7db631e3c5959b46b047a32f170b69442761771fc387ad5a3dc2075b2da4c681b52b0289fcd
Via: 1.0 d5ba42a2d3d506b64c73b6035a0a9f60.cloudfront.net:11180 (CloudFront), 1.0 f564d0c1e4568b2b822f986a309f4114.cloudfront.net:11180 (CloudFront)
Connection: close

compare to:

➔ curl --head https://dmk3f228gizbf.cloudfront.net/assets/html5-5ec848fc9e0b171444e2d3115e0cbb23.js
HTTP/1.0 200 OK
Server: nginx
Date: Fri, 09 Dec 2011 04:11:20 GMT
Content-Type: application/x-javascript
Content-Length: 1521
Last-Modified: Thu, 24 Nov 2011 15:23:30 GMT
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes
Vary: Accept-Encoding
X-Cache: Miss from cloudfront
X-Amz-Cf-Id: 44aa1e785346768996718dc3b167e27b9f1ad81c4e104ae17bf12b11c06d051a4101f21f1af6be1b,921b2c35c4278df6a19de42b5a5b7cbf9e8602ef95e91fbb6044a199f8697eaaea05767076bdc37c
Via: 1.0 e81b6793c2bc2378a5c7ea08e930ec3d.cloudfront.net:11180 (CloudFront), 1.0 38725119ff70beb3d62fd652f133ae0b.cloudfront.net:11180 (CloudFront)
Connection: close

If you are using your own server as the cloudfront origin, you just need to configure this on your server and cloudfront will pick it up. If you are manually putting stuff on and configuring cloudfront with s3/the api, then you configure it with the api, i don't have much experience with it but it's probably easy to google.

You should set it to far future, since the versioning is controlled by the URL in the case of this library file.

In summary -- a small configuration change will increase the loading performance of the library by 150-200 ms! Let me know if you need any help configuring this.

Cheers,
John