简体   繁体   English

是否有一个html标签可以告诉浏览器缓存我的html和css文件?

[英]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.

相关问题 我可以告诉 browser-sync 始终使用一个 .html 文件吗? (对于 html5mode 链接) - Can I tell browser-sync to always use one .html file? (for html5mode links) Html 文件和 css 实现无法在我的 chrome 浏览器上正确显示 - Html file and css implementation not displaying correctly on my chrome browser 是否在html文件中包含no cache meta标签还可以防止该html文件中链接的js和css文件被缓存? - Does including the no cache meta tag in an html file also prevent the js and css files linked in that html file from being cached? Html 音频标签和缓存 - Html Audio Tag and cache 如何在JavaScript中以编程方式判断从哪个文件中将特定CSS类应用于HTML元素? - How can I programmatically tell, in JavaScript, from which file a particular CSS class is getting applied to an HTML element? 我可以在 html 表单输入字段中显示我的文本文件数据吗? 如果是,请告诉我怎么做? - can i display my text file data in html form input field? if yes, please tell me how? 无法使用gulp-inline-css将CSS内联到html文件中的样式标签 - CSS can't be inlined to style tag in html file using gulp-inline-css 如何在浏览器中编辑 javascript,就像我可以使用 Firebug 编辑 CSS/HTML 一样? - How can I edit javascript in my browser like I can use Firebug to edit CSS/HTML? HTML - 如何检查文件(.js或.css)是否已从缓存中加载或拾取? - HTML - How can I check if a file (.js or .css) was loaded or picked up from the cache? 从服务器加载已经存在的 HTML 文件而不是浏览器缓存 - Load already live HTML file from server instead of browser cache
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM