[英]Is there a html tag that can tell browser to cache my html and or css file?
So far I read about js and css browser caching need to be enabled by things like server side setting .htaccess. 到目前为止,我读到有关js和CSS浏览器缓存的信息,需要通过服务器端设置.htaccess启用。 Is there no way to just add a html tag / config on the html page or js config to tell browser to do that (ie cache my js and css for certain period of time or indefinitely)?
有没有办法只是在html页面或js配置上添加html标签/配置来告诉浏览器做到这一点(即,将我的js和css缓存一段时间或无限期地缓存)?
No. You can ask a browser not to cache a page, but the browser may not have the storage space available to be able to cache your page. 不可以 。您可以要求浏览器不要缓存页面,但是浏览器可能没有可用的存储空间来缓存页面。 If it's secure to do so, and the browser has the space available, it will ordinarily cache the page unless asked not to.
如果这样做是安全的,并且浏览器有可用的空间,则通常会缓存该页面,除非要求不要这样做。 By the same manner, you can place limits on the maximum time a page should be cached for, but not a minimum time.
通过相同的方式,您可以限制页面应缓存的最长时间,而不是最短时间。
Even requesting not to cache pages should be done via an HTTP header (eg by .htaccess) though, and not through a <meta>
element. 即使是请求不缓存页面,也应该通过HTTP标头(例如,通过.htaccess)而不是通过
<meta>
元素来完成。 The cache control meta elements are obsolete in HTML5, because only browsers will read them. 缓存控件元元素在HTML5中已过时,因为只有浏览器才能读取它们。 Which means that network proxies won't know not to cache the files.
这意味着网络代理将不知道不缓存文件。
Furthermore. 此外。 as @dpix points out in the comments, a
<meta>
element is only good for HTML files, and not other resources. 正如@dpix在注释中指出的那样,
<meta>
元素仅适用于HTML文件,不适用于其他资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.