• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

js browser cache

MattW

Well-known member
#1
I'm hitting a stumbling block with regards to getting my caching working properly.

I'm currently using Apache 2.2.25 with Nginxcp for reverse proxy with WHM/Cpanel

Looking at xenforo.js here

Code:
Request URL:http://xenforo.com/community/js/xenforo/min/xenforo.js?_v=760e047a
Request Method:GET
Status Code:200 OK (from cache)
Request Headersview source
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
Query String Parametersview sourceview URL encoded
_v:760e047a
Response Headersview source
Accept-Ranges:bytes
Content-Encoding:gzip
Content-Length:47443
Content-Type:text/javascript
Date:Thu, 29 Aug 2013 17:14:37 GMT
ETag:"2403ce-24e2e-4e515a30cdce1"
Last-Modified:Thu, 29 Aug 2013 12:56:39 GMT
Server:Apache
Vary:Accept-Encoding
and the same from my server
Code:
Request URL:http://js.z22se.com/js/xenforo/xenforo.js?_v=ea2255a7
Request Method:GET
Status Code:304 Not Modified
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en,en-GB;q=0.8
Connection:keep-alive
Cookie:xf_session=feba5673b4293aee2d5f75f03495e45e; __utma=46995516.665014763.1377795315.1377795315.1377795315.1; __utmb=46995516.1.10.1377795315; __utmc=46995516; __utmz=46995516.1377795315.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Host:js.z22se.com
If-Modified-Since:Tue, 20 Aug 2013 05:00:20 GMT
Referer:http://www.z22se.co.uk/find-new/1913224/posts
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
Query String Parametersview sourceview URL encoded
_v:ea2255a7
Response Headersview source
Cache-Control:max-age=0
Connection:keep-alive
Date:Thu, 29 Aug 2013 17:18:41 GMT
Expires:Thu, 29 Aug 2013 17:18:41 GMT
Server:nginx admin
I've removed nginx to troubleshoot, and it's only my z22se site on the server having this problem, where it's returning a 304 for all the js stuff.

Any idea where I should be looking for what is causing this? I've got nothing in my .htaccess file.
 

MattW

Well-known member
#2
Hmm, infact, it looks like my browser may have cached something from a while back (old .htaccess) as I've emptied everything out, and it's now returning a 200 response and loading from cache (y)
 

Floren

Well-known member
#5
Matt, can you help me understand what are you trying to cache?
For example, I always get 200:
Code:
$ curl -I https://www.axivo.com/community/js/xenforo/xenforo.js?_v=59e72362
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 02 Oct 2013 02:38:33 GMT
Content-Type: application/x-javascript
Content-Length: 151078
Last-Modified: Wed, 25 Sep 2013 02:14:24 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "52424700-24e26"
Expires: Thu, 02 Oct 2014 02:38:33 GMT
Cache-Control: max-age=31536000
Cache-Control: public
Pragma: public
Accept-Ranges: bytes
 

MattW

Well-known member
#6
Matt, can you help me understand what are you trying to cache?
For example, I always get 200:
Code:
$ curl -I https://www.axivo.com/community/js/xenforo/xenforo.js?_v=59e72362
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 02 Oct 2013 02:38:33 GMT
Content-Type: application/x-javascript
Content-Length: 151078
Last-Modified: Wed, 25 Sep 2013 02:14:24 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "52424700-24e26"
Expires: Thu, 02 Oct 2014 02:38:33 GMT
Cache-Control: max-age=31536000
Cache-Control: public
Pragma: public
Accept-Ranges: bytes
I was trying to basically get as much as possible to cache in Chrome, such as the js files and images.

Ages ago, I added some entries into .htaccess that seemed to mess up the responses that were being sent back to the browser. It was always sending a 304 response with a max-age=0, and being fetched each time the page reloaded.

Now, almost everything is showing a 200 response, and being cached by the browser
200_response.PNG

Looking at my old set up notes, this is what I'd put in my .htaccess

Code:
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 5 weeks
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A3024000
Header append Cache-Control "public"
</FilesMatch>

# Set up caching on media files for 5 weeks
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A3024000
Header append Cache-Control "public"
</FilesMatch>

# Set up 1 day caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A604800
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
Removing all of that fixed the issue.