2

We had a production release and there were issues due to javascript that we updated. The clients have an old cached version of the javascript file which is causing the issue. The workaround is to have them refresh their browser cache (hit F5) but Im trying to understand how long the javascript gets cached by default.

I do not see the cache-control headers or Expired header being set on the server side and I do not see those headers in the developer console in chrome. I DO see the below meta tags are set on the page. These meta tags would lead me to believe the JS is not cached - however we know it is because we have many users reporting issues and hitting F5 fixes it.

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

So back to my original question - how long is the javascript going to be cached by default if we set no cache headers. I apologize since Im sure this question is asked elsewhere I just cant seem to find a concrete answer. Here are all the headers I can see being set:

Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:157271
Content-Type:application/x-javascript
Date:Tue, 23 Feb 2016 15:37:38 GMT
Keep-Alive:timeout=15, max=500
Last-Modified:Sat, 20 Feb 2016 10:57:45 GMT
Strict-Transport-Security:max-age=31536000; includeSubDomains
X-Content-Type-Options:nosniff
George
  • 1,021
  • 15
  • 32
  • If those are the response headers for the HTTP request made for the JavaScript source, then the browser might keep it forever. There are no headers to set an expiration date, no "if modified since" header, etc. – Pointy Feb 23 '16 at 15:59
  • 1
    Note that the headers for the HTTP *page* that includes the ` – Pointy Feb 23 '16 at 16:00
  • 1
    http://stackoverflow.com/questions/2869800/how-long-are-files-usually-kept-in-a-browsers-cache your answer given here – Onur Feb 23 '16 at 16:01
  • @Onur yes, though this OP might want to ask the more useful question, "How do I control how long JavaScript files are cached?", since (judging by those headers) nothing's being done right now. – Pointy Feb 23 '16 at 16:02
  • you can use Cache-Control and Expires headers for this – Onur Feb 23 '16 at 16:05
  • no my original question is the question I intended to ask. I know how to add cache headers. The problem is the old javascript is already cached on clients machines and need to find out how long since the old javascript is throwing exceptions. – George Feb 25 '16 at 05:45

1 Answers1

1

Im aware of how to add cache headers. We have a production issue affecting many clients. For a large site its no small thing to migrate the fix to production. I am trying to find out how long the browser cached by default because that is how long the issue will exist for our clients before the browser will naturally refetch the newer version of the javascript if we do not migrate the fix. For instance if it was 2 days then the issue would already have cleared itself up without us taking action.

Seems like the answer was right in front of me though. There are no cache headers but the below tag seems to be saying cache forever regardless of the no-cache meta tags right before it.

<meta http-equiv="expires" content="0">

So we have to do a production migration and add cache busters to all our javascript to fix the issue or keep telling every client to refresh the page.

George
  • 1,021
  • 15
  • 32
  • The first paragraph of your answer sounds like it should go in the question. – Bergi Feb 25 '16 at 07:07
  • 1
    That `` tag is not in your javascript files I presume? It only affects the HTML resource it is included in. – Bergi Feb 25 '16 at 07:08