利用浏览器缓存来存储外部文件 [英] Leverage browser caching for external files

查看:92
本文介绍了利用浏览器缓存来存储外部文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的google页面速​​度洞察力评级为良好,但是我也希望将一些外部文件也进行缓存,有人知道什么是处理此问题的最佳方法吗?

i'm trying to get my google page speed insights rating to be decent, but there are some external files that i would want to be cached aswell, anyone knows what would be the best way to deal with this?

https://s.swiftypecdn.com/cc.js (5 minutes)
https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js (60 minutes)
https://pagead2.googlesyndication.com/pagead/osd.js (60 minutes)
https://www.google-analytics.com/plugins/ua/linkid.js (60 minutes)
https://hey.hellobar.com/…d5837892514411fd16abbb3f71f0d400607f8f0b (2 hours)
https://www.google-analytics.com/analytics.js (2 hours)


推荐答案

复制到服务器并使用不同的浏览器缓存设置在本地或通过CDN提供服务。

Copy to your server and serve locally or from CDN, with different browser cache settings. Update GA scripts periodically with cronjob or something similar.

在Wordpress上,有一些插件可以为您完成此任务,例如:折叠之上;他们称此功能为 Javascript本地化

On Wordpress there are plugins that can do that for you, like this one: Above The Fold; they call this feature Javascript localization.

另一方面,我在服务器上使用Google Pagespeed模块,指令为 MapProxyDomain 替代性异步跟踪代码段。对我来说,这似乎很优雅。

On the other hand, I use Google Pagespeed Module on server and it's directive MapProxyDomain in combination with Alternative async tracking snippet. That seems most elegant for me.

这应该足以让您开始解决问题。

This should be enough for you to start solving your problem.

这篇关于利用浏览器缓存来存储外部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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