动态脚本插入&缓存(兰迪?) [英] Dynamic Script Insertion & caching (Randy?)

查看:63
本文介绍了动态脚本插入&缓存(兰迪?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在玩动态脚本插入来向

服务器发出请求,要求自动运行JavaScript文件它在浏览器中到达

。它工作但是...


页面缓存太好了。当我重新访问页面或刷新

页面,然后重做脚本插入时,浏览器甚至没有点击服务器上的b $ b来检查更新的版本JavaScript文件。

相同的旧脚本随每次插入运行。


如果我在页面中重复插入相同的脚本(没有页面)

重新加载)服务器没有找到更新的版本,但每次运行

脚本。


如果我附加一个随机的查询字符串编号到脚本的URL

然后命中服务器。但是如果剧本没有改变,那就是

不必要的下载浪费,因为缓存的版本永远不会使用



任何关于让缓存更好地运行动态脚本的想法

插入?


谢谢,

彼得

Hi,

I''m playing with dynamic script insertion to make a request to the
server for a JavaScript file to be automatically run when it arrives
in the browser. It works but...

The page caching is too good. When I revisit the page or refresh the
page, and then redo the script insertion, the browser doesn''t even hit
the server to check for a newer version of the JavaScript file. The
same old script runs with each insertion.

If I insert the same script in a page repeatedly (without a page
reload) the server is not hit looking for a newer version but the
script does run each time.

If I attach a query string with a random number to the script''s URL
then the server is hit. However if the script hasn''t changed this is
an unnecessary waste of download because the cached version never gets
used.

Any ideas on getting caching working better for dynamic script
insertion?

Thanks,
Peter

推荐答案

Peter Michaux写道:
Peter Michaux wrote:




我正在玩动态脚本插入来向

服务器发出请求,要求JavaScript文件在到达时自动运行

在浏览器中。它工作但是...


页面缓存太好了。当我重新访问页面或刷新

页面,然后重做脚本插入时,浏览器甚至没有点击服务器上的b $ b来检查更新的版本JavaScript文件。

相同的旧脚本随每次插入运行。


如果我在页面中重复插入相同的脚本(没有页面)

重新加载)服务器没有找到更新的版本,但每次运行

脚本。


如果我附加一个随机的查询字符串编号到脚本的URL

然后命中服务器。但是如果剧本没有改变,那就是

不必要的下载浪费,因为缓存的版本永远不会使用



任何关于让缓存更好地运行动态脚本的想法

插入?


谢谢,

彼得
Hi,

I''m playing with dynamic script insertion to make a request to the
server for a JavaScript file to be automatically run when it arrives
in the browser. It works but...

The page caching is too good. When I revisit the page or refresh the
page, and then redo the script insertion, the browser doesn''t even hit
the server to check for a newer version of the JavaScript file. The
same old script runs with each insertion.

If I insert the same script in a page repeatedly (without a page
reload) the server is not hit looking for a newer version but the
script does run each time.

If I attach a query string with a random number to the script''s URL
then the server is hit. However if the script hasn''t changed this is
an unnecessary waste of download because the cached version never gets
used.

Any ideas on getting caching working better for dynamic script
insertion?

Thanks,
Peter



var timestamp = new Date();

var headID = document.getElementsByTagName(" head")[0];

var newScript = document.createElement(''script'');

newScript.src =

''http://www.somedomain.com/somescript.js ?''+ timestamp.getTime();

headID.appendChild(newScript);

唯一的网址将覆盖缓存。


-
http://www.hunlock.com - Javascript,CSS中的冥想。

var timestamp = new Date();
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement(''script'');
newScript.src =
''http://www.somedomain.com/somescript.js?''+timestamp.getTime();
headID.appendChild(newScript);
The unique url will foil the cache.

--
http://www.hunlock.com -- Musings in Javascript, CSS.


FA
FA


2007年2月1日05:47:18 -0800," ; Peter Michaux < pe ********** @ gmail.com>

写道:
On 1 Feb 2007 05:47:18 -0800, "Peter Michaux" <pe**********@gmail.com>
wrote:

>如果我附上一个查询带有随机数的字符串到脚本的URL
然后服务器被命中。但是,如果脚本没有改变,这是不必要的下载浪费,因为缓存的版本永远不会被使用。

任何关于让缓存更好地运行动态脚本的想法
插入?
>If I attach a query string with a random number to the script''s URL
then the server is hit. However if the script hasn''t changed this is
an unnecessary waste of download because the cached version never gets
used.

Any ideas on getting caching working better for dynamic script
insertion?



确保服务器发送的标题是合适的 - 例如

必须重新验证


吉姆。

Make sure the headers sent by the server are appropriate - e.g.
must-revalidate

Jim.


这篇关于动态脚本插入&amp;缓存(兰迪?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆