将随机数添加到.css,以便它不会缓存 [英] Add random number to .css so it doesn't cache

查看:267
本文介绍了将随机数添加到.css,以便它不会缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让styles.css不缓存,因为服务器在缓存时遇到css问题。

I'm trying to get the styles.css to not cache as the server is having issues with the css when it caches.

<script>
var numBAH = Math.floor(Math.random()*100);
</script>

<link href="styles.css+ numBAH +" rel="stylesheet" type="text/css" />


推荐答案

如果您可以访问服务器端语言使用查询字符串呈现链接标记会更整洁,该查询字符串是文件整个内容的哈希值。这样,只有当文件的内容实际发生了变化时,缓存无效器ey才会改变。

If you have access to a server-side language it would be neater to render the link tag with a query string that is a hash of the entire content of the file. In that way, the cache invalidator ey will change only when the content of the file has actually changed.

看过之后关于你永远想要如何使用缓存的讨论,因为它加载太快,我想改变我的答案。不要新的Date(),但要:修复你的页面,以便快速加载是一个理想的结果。如果您遇到特定问题,请创建一个针对这些问题的问题,不要直接针对糟糕的解决方法。

After having seen the discussion that has followed, about how you never want to use cache, because it loads too quickly, I want to change my answer. Not to new Date(), but to: fix your page so that loading quickly is a desired result. If you're having specific problems with that, create a question that targets those problems, don't go directly for the lousy workaround.

这篇关于将随机数添加到.css,以便它不会缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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