YUI 框架的 ie8 Javascript 缓存问题

发布于 2024-12-01 06:02:21 字数 628 浏览 0 评论 0原文

我正在运行一个使用 YUI js 框架 (v3.0) 的应用程序。用户可以单击我的应用程序中的按钮,将其升级到框架的最新版本(3.4)。问题是在 ie8 上我遇到了一些奇怪的 javascript 错误。调试后,似乎从浏览器缓存中检索了 loader-min.js 文件的旧版本(3.0),因为它在实例化时仍被 YUI 对象使用。因此,在升级过程中,我创建了一个脚本节点,将位置添加到新的加载程序文件 (3.4),然后将其插入到 head 部分。我想我们都熟悉这项技术。但是,当用户导航到下一页时,加载的文件会丢失,旧版本(3.0)仍保留在缓存中。已通过使用开发人员工具并查看应用程序已加载的所有 JavaScript 文件验证了这一点。

我已经尝试了很多不同的方法来获取我正在加载的新版本(3.4)以覆盖当前缓存中的版本,这将解决 javascript 问题。我尝试在正在加载的文件名末尾添加一个唯一的字符串,这通常是 js 文件“版本控制”的方式。我已确保我尝试加载的新版本的 Etag 和 Cache-Control 标头已设置。什么都不起作用,我正用头撞墙。

有一个小限制,我必须使用 javascript 来尝试加载这个新版本的 loader-min 文件。由于升级过程的工作方式,我无法将简单的脚本标记添加到我的 html 中。关于为什么 IE8 不会缓存我动态加载的版本有什么想法、想法或指示吗?

I have an application running that is using the YUI js framwork (v3.0). The user can click a button within my app which will upgrade them to the latest version of the framework (3.4). The problem is that on ie8 I'm getting some strange javascript errors. After debugging it seems that an old version (3.0) of the loader-min.js file is retrieved from the browser cache as it still being used by the YUI object when it's instantiated. So during my upgrade I create a script node, add the location to the new loader file (3.4), and then insert it into the head section. Think we're all familiar with this technique. However, when the user navigates to the next page, the file that is loaded is lost and the old version (3.0) still remains in the cache. Have verified this by using developer tools and looking at all the javascript files the app has loaded.

I've tried lots of different things to get the new version (3.4) I'm loading to override the version currently in cache, which will fix the javascript issues. I've tried adding a unique string to the end of the file name that is being loaded which is typically how js files can be 'versioned'. I've made sure the Etag and Cache-Control headers for the new version I'm trying to load have been set. Nothing works and I'm banging my head against the wall.

One small restriction, I have to use javascript to try and load this new version of the loader-min file. I cannot add a simple script tag to my html because of how the upgrade process works. Any thoughts, ideas, pointers as to why IE8 will not cache the version I am loading dynamically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰魂雪魄 2024-12-08 06:02:21

像这样的缓存问题通常可以通过为新版本的脚本指定一个不同的文件名(通常包含版本号)并更改包含该文件名的 HTML 来引用新文件名来解决,这样它就不会与旧版本混淆。缓存系统。

事实上,这个版本系统可能应该用于所有外部脚本文件,因此当您升级它们时,您可以确保查看者立即获得新版本,并且脚本的旧/新版本永远不会被缓存系统意外混合。

Caching problems like this are normally solved by giving the new version of the script a different filename (often containing the version number) and changing the HTML that includes it to reference the new filename so that it can never be confused with the old version by a caching system.

In fact, this version system should probably be used on all external script files so when you upgrade them, you can make sure that viewers get the new version immediately and old/new versions of the scripts are never accidentally mixed by a caching system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文