缓存特定的 Javascript 和 CSS 文件 [英] Caching specific Javascript and CSS files

查看:35
本文介绍了缓存特定的 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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