javascript 将缓存控制设置为外部资源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9580307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:06:43  来源:igfitidea点击:

set cache-control to external resources?

javascriptjquerycache-control

提问by Toni Michel Caubet

@tools.pingdom.com I get a warning in leverage cache-control because of these resources:

@tools.pingdom.com 由于这些资源,我在利用缓存控制时收到警告:

http://code.jquery.com/jquery-1.6.2.min.js
http://www.google-analytics.com/ga.js
http://edge.sharethis.com/images/spinner.gif
http://w.sharethis.com/button/buttons.js

Which are not in my host.

哪些不在我的主机中。

What can I do about this?

我该怎么办?

This is the beginning of my htaccess:

这是我的htaccess的开始:

# 480 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>

# 1 weeks
<FilesMatch "\.(js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

回答by Corbin

You can't control the headers sent from a server that you don't control.

您无法控制从您无法控制的服务器发送的标头。

In other words, either host a copy yourself or there's nothing you can do about it.

换句话说,要么自己托管副本,要么对此无能为力。

回答by onlinecasinoselite

You can grab the code from the resources and serve them from your site directly, in these way you can manage the cache, but if some update occurs from the sites related to the resources, you miss it, or you have to control everytime ..chose at your convenience.

您可以从资源中获取代码并直接从您的站点为它们提供服务,通过这种方式您可以管理缓存,但是如果与资源相关的站点发生了某些更新,您就会错过它,或者您每次都必须控制..在您方便的时候选择。

回答by user2787614

You can try copy their scripts and host them youself. Just write a script and add it to cron to load new versions automaticly. Working on it now myself.

您可以尝试复制他们的脚本并自己托管。只需编写一个脚本并将其添加到 cron 即可自动加载新版本。现在我自己在努力。