Only IE is caching pages from my server?

Never noticed this before until today when I started messing around with CKEditor - which is close to a 500kb javascript file - but long story short it seems like browsers are not properly caching content from my Apache server. Here are 2 examples …

This is just a page with an image, and caching seems to work fine:

http://www.fmmediainc.com/sunset.html

Next is a test page containing a CKEditor instance, and it loads the entire 500kb javascript file and all the other supporting files every time you load the page. The only browser that DOES cache this page properly is IE:

http://www.fmmediainc.com/ckeditor.html

Various other pages don’t seem to be cached properly either, but I think the above examples illustrates the problem.

Is this something I’ve messed up in my Apache config or ??

When I use the CKEditor demo over at ckeditor.com everything is cached as normal in my browser, and subsequent loads of their demo page appear almost instantly, so I assume it has to be something with my server.

Anyone have any ideas? It’s driving me crazy!

Ok this is driving me crazy and I could REALLY use some help here.

Simple example based on ckeditor.js which I’ve been playing around with today:

http://www.fmmediainc.com/misc/js/ckeditor/ckeditor.js

This is a ~500kb javascript file and no browsers (except IE go figure) are caching this javascript file from my server. So every time I load the page it is reloading the 500kb file which is ridiculous.

It seems like my Apache server is sending a new Last-Modified header on every request, even though the file hasn’t changed. For example I just loaded the file and here’s the Last-Modified header:

Last-Modified:Tue, 11 Feb 2014 05:05:57 GMT

Now if I reload the page a few seconds later the Last-Modified header is:

Last-Modified:Tue, 11 Feb 2014 05:06:08 GMT

Basically the Last-Modified header and the Date headers are always the same, which is bizarre.

Anyone have any ideas? I’ve been googling and search on stackoverflow, etc. for hours with no luck.

All URLs in this thread are failing for me (HTTP 404).

Anyway, are you serving the file as plain javascript file, or are you serving it through PHP?
If you’re serving it as a plain javascript file, I recommend looking at ExpiresByType
If you’re serving it using PHP you’d add something like this to your PHP


<?php
$expire = 'Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+10 years')) . ' GMT';
header($expire);

Thanks for the reply. I removed those pages because I thought I solved the problem, but it came right back as soon as I updated the main 500k ckeditor javascript file. So based on what’s happening now, it seems like browsers are only caching javascript files after some set period of time (it seemed about 4-6 hours if I remember correctly) and until such time has passed it fetches the file every time. Do you know if this is something all the main browsers are doing on their own, or is it something caused by the headers my server is sending out?

If I use ExpiresByType to set a 1 year expiration date for js files for example, will browsers still check to see if there’s a newer version, or will they just automatically use whatever is in the cache for the next full year - requiring me to change filenames etc. if I want browsers to fetch an updated file (huge hassle)

The latter - if you tell a browser it can cache it for a year it will cache it for a year (unless it gets evicted from cache because the cache is full) and will not check with the server if there’s a newer version.
What you can do is append a query string, like


<script type="text/javascript" src="/path/to/my/javascript.js[color="red"]?v=2[/color]"></script>

En then every time you update the script change 2 to 3, than 4, than 5, etc.
Which is a lot easier than changing the filename every time.

Thanks. I’ve seen that. In my research I’ve also seen something about “conditional requests” in regards to caching. That seems to be what I want - but I can’t figure out if that’s something you can make happen on the server side or is it just a client side thing depending on the browser, etc. Do you know anything about that?