admin管理员组文章数量:1279046
We recently moved to jQuery 1.6 and ran into the attr() versus prop() back-pat issue. During the first few hours after the change was deployed everything was fine, then it started breaking for people. We identified the problem pretty quickly and updated the offending JS, which was inline.
No we have a situation where some folks are still having issues. In every case thus far, I could get the user up and running again by telling them to load the page in question then manually refresh it in the browser. So something must still be cached somewhere.
But there are basically only two potential culprits: First, the jQuery library itself, but this is loaded with the version number in the query string so I think browsers will be refreshing it in their cache. Second, the inline javascript. Is it possible that this is being cached in the browser?
We are using APC, apc.stat=1 so it should be detecting that the PHP files have changed. Just to be on the safe side I nuked the opcode cache anyway.
To summarize, I have two questions:
- Could some browsers be ignoring the query string when jQuery is loaded?
- Could some browsers be caching an older version of the inline javascript?
Any other ideas very wele too.
UPDATE: In the course of checking that there wasn't any unexpected caching going on using Firebug, I discovered a case where the old jQuery library would load. That doesn't explain why we had trouble after deploying the site and before we updated the inline code, but if it solves the problem I'll take it.
We recently moved to jQuery 1.6 and ran into the attr() versus prop() back-pat issue. During the first few hours after the change was deployed everything was fine, then it started breaking for people. We identified the problem pretty quickly and updated the offending JS, which was inline.
No we have a situation where some folks are still having issues. In every case thus far, I could get the user up and running again by telling them to load the page in question then manually refresh it in the browser. So something must still be cached somewhere.
But there are basically only two potential culprits: First, the jQuery library itself, but this is loaded with the version number in the query string so I think browsers will be refreshing it in their cache. Second, the inline javascript. Is it possible that this is being cached in the browser?
We are using APC, apc.stat=1 so it should be detecting that the PHP files have changed. Just to be on the safe side I nuked the opcode cache anyway.
To summarize, I have two questions:
- Could some browsers be ignoring the query string when jQuery is loaded?
- Could some browsers be caching an older version of the inline javascript?
Any other ideas very wele too.
UPDATE: In the course of checking that there wasn't any unexpected caching going on using Firebug, I discovered a case where the old jQuery library would load. That doesn't explain why we had trouble after deploying the site and before we updated the inline code, but if it solves the problem I'll take it.
Share Improve this question edited Jul 27, 2011 at 4:38 Greg asked Jul 27, 2011 at 3:45 GregGreg 2,5634 gold badges22 silver badges27 bronze badges 8- If it was inline and that code was the real culprit, the actual file that contained it would have to be what was cached. – Jared Farrish Commented Jul 27, 2011 at 3:46
- 2 It sounds like your page is being cached, not specifically the inline JS... – Zachary Commented Jul 27, 2011 at 3:49
- Have you thought of browser caching headers? This makes the most sense to me. – Evert Commented Jul 27, 2011 at 3:50
- The page in question is PHP, so it must be executed every time the page is loaded. I don't understand how that will be cached. It is possible that I'm missing something fundamental about the caching mechanism. – Greg Commented Jul 27, 2011 at 3:55
- @Greg, can you give me a link to the page? I'll tell you if my browser caches it. – Paul Commented Jul 27, 2011 at 4:04
2 Answers
Reset to default 9The answer to both your questions is no. Unless the whole page is being cached as well.
If that's the case you could try sending some headers along with your page that tell browsers not to cache it.
I'd say the answers to your questions are 1) No and 2) Yes.
jQuery versions are different URLs so there's no caching problems there unless you somehow edit a jQuery file directly without changing the version string.
Browser pages (including inline javascript) will get cached according to both the page settings and the browser settings (that's what browsers do). The inline javascript isn't cached separately, but if the web page is cached, then the inline javascript is cached with it. What kind of permissible caching have you set for your web pages (either in meta tags or via http headers)?
Lots to read on the subject of web page cache control here and here if needed.
It is very important to plan/design an upgrade strategy when you want to roll out upgrades that works properly with cached files in the browser. Doing this wrong can result in your user either staying on old content/code until caches expire or even worse ending with a mix of old/new content/code that doesn't work.
The safest thing to do is to change source URLs when you have new content. Then there is zero possibility that an old cached page will ever get the new content so you avoid the mixing possibility. For example, on the Smugmug photo sharing web site, whenever any site owner updates an image to a new version of the image, a version number in the image URL is changed. Then, when the source page that shows that image is served from the web server, it includes the new image URL so, no matter whether the old version of the image is in the browser cache or not, the new version image is shown to the user.
It is obviously not always practical to change the URL of all pages (especially top level pages) so those pages often have to be set with short cache settings so the browsers won't cache them for long and they will regularly pull fresh content.
本文标签: Do browsers cache inline Javascriptand if sohow to force a reloadStack Overflow
版权声明:本文标题:Do browsers cache inline Javascript, and if so, how to force a reload? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741249672a2365557.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论