缓存特定的 Javascript 和 CSS 文件

编程入门 行业动态 更新时间:2024-10-21 17:21:10
本文介绍了缓存特定的 Javascript 和 CSS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何缓存一些特定的 JavaScript &CSS 文件.我从这个网站找到了建议把它放在我的 .htaccess 文件中

How can I cache a few specific JavaScript & CSS files. I found advice from this site to put this in my .htaccess file

AddOutputFilter DEFLATE css js ExpiresActive On ExpiresByType application/x-javascript A2592000

但它是不完整的.什么是 .htaccess 以及如何在我的 Web 根文件夹中创建它、将其存储在何处?

But it is incomplete. What is .htaccess and how do I create it, where to store it, in my web root folder?

下列语句的含义是什么:

What is the meaning of the following statements:

AddOutputFilter DEFLATE css js ExpiresActive On ExpiresByType application/x-javascript A2592000

我不想缓存我所有的 Javascript &CSS 文件,而只是一些永远不会改变的特定文件.

I dont want to cache all my Javascript & CSS files rather just a few specific files which will never change.

我该怎么做?

推荐答案

您可以将 IIS 配置为按扩展名缓存特定文件.例如:

You can configure IIS to cache specific files by extension. For example:

选择您的 css/js 文件所在的文件夹,然后单击输出缓存".

Select the folder where your css/js files reside and then click on Output Caching.

然后添加要缓存的文件扩展名:

Then add the file extensions that you want to cache:

我认为除非您编写一个 http handler 模块来独立地为每个文件添加适当的标头,否则您无法在每个文件的基础上指定要缓存的内容,但是从 IIS 开始,这就是完成了.

I don't think you can specify which ones to cache on a per file basis unless you write an http handler module to add the appropriate headers for each file independently, but from IIS this is how is done.

然后,您可以使用 firebug/fiddler 或您选择的工具来验证您是否收到了 304 响应.

Then you can verify that you are getting 304 responses using firebug / fiddler or your tool of choice.

我希望这会有所帮助.

更多推荐

缓存特定的 Javascript 和 CSS 文件

本文发布于:2023-11-01 01:32:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   文件   Javascript   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!