cdn的清理cdn缓存_JavaScript CDN后备

cdn的清理cdn缓存

CDNs are great for pulling shared resources from, especially JavaScript libraries. The advantage in the likelihood that a file is already cached before the user gets to our site is huge. The only problem with using a CDN is that it's out of control; more specifically, what if the CDN server is down? What a nightmare! Thousands if not millions of websites would be hurt...but not yours. Nope, you added a CDN fallback so that a failed CDN wouldn't hurt your site!

CDN非常适合从中获取共享资源,尤其是JavaScript库。 在用户到达我们的网站之前已经缓存了文件的优势是巨大的。 使用CDN的唯一问题是,它不受控制。 更具体地说,如果CDN服务器已关闭怎么办? 什么样的恶梦! 数以千计甚至数百万个网站可能会受到伤害……但您的网站却没有受到伤害。 不会,您添加了CDN后备功能,以便CDN失败不会损害您的网站!

HTML / JavaScript (The HTML / JavaScript)

The document.write method is one you generally want to avoid, but it works best in this case:

通常您希望避免使用document.write方法,但是在这种情况下,它最有效:


<!-- Use Google CDN for MooTools, local Moo as a callback -->
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js"></script>
<script>!window.MooTools && document.write(unescape('%3Cscript src="/js/mootools-yui-compressed.js"%3E%3C/script%3E'))</script>


In the event that the CDN fails, your local file is instead used. Simple but clever fallback, yes? The likelihood that Google or other CDNs is down is small, but since you don't control the other server, there's always that risk! Play it safe!

如果CDN失败,则改用您的本地文件。 简单但明智的后备,是吗? Google或其他CDN宕机的可能性很小,但是由于您不控制其他服务器,因此总会有这种风险! 安全播放!

翻译自: https://davidwalsh.name/cdn-fallbacks

cdn的清理cdn缓存

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值