"Expires" in the http header for static content? as

What is the best way to add โ€œExpiresโ€ in the HTTP header for static content? eg. images, css, js

Web server - IIS 6.0; classic ASP language

+4
source share
6 answers

You can try something like this:

@ECHO OFF REM --------------------------------------------------------------------------- REM Caching - sets the caching on static files in a web site REM syntax REM Caching.CMD 1 d:\sites\MySite\WWWRoot\*.CSS REM REM %1 is the WebSite ID REM %2 is the path & Wildcard - for example, d:\sites\MySite\WWWRoot\*.CSS REM _adsutil is the path to ADSUtil.VBS REM --------------------------------------------------------------------------- SETLOCAL SET _adsutil=D:\Apps\Scripts\adsutil.vbs FOR %%i IN (%2) DO ( ECHO Setting Caching on %%~ni%%~xi CSCRIPT %_adsutil% CREATE W3SVC/%1/root/%%~ni%%~xi "IIsWebFile" CSCRIPT %_adsutil% SET W3SVC/%1/root/%%~ni%%~xi/HttpExpires "D, 0x69780" ECHO. ) 

Which sets the caching value for each CSS file in the root directory of the website for up to 5 days, then do it like this:

 Caching.CMD 1 \site\wwwroot\*.css Caching.CMD 1 \site\wwwroot\*.js Caching.CMD 1 \site\wwwroot\*.html Caching.CMD 1 \site\wwwroot\*.htm Caching.CMD 1 \site\wwwroot\*.gif Caching.CMD 1 \site\wwwroot\*.jpg 

The view is painful, but efficient.

BTW - to get the value for HttpExpires, set the value in the GUI, then run

 AdsUtil.vbs ENUM W3SVC/1/root/File.txt 

to get the desired value

+5
source

I think this is what you need, this is the expiration of the content in the HTTP headers in IIS Manager. I am using a static content template in a folder like ~ / Resources and setting expiration dates in this particular folder to have a much longer life than the rest of the application.

Here's a link to the entire article: IIS 6.0 F1: Website Properties - HTTP Headers Tab

+3
source

in the IIS administrator, you can set it for each type of file, or you can (for dynamic, for example aspx) do this in code. After setting up, you should check the headers that are displayed with a tool like the Mozilla firefox + live headers plugin, or you can use a web tool like http://www.httpviewer.net/

0
source

For others coming from google: this will not work in iis6 , but works in 7 and above.

In your web.config:

 <staticContent> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> </staticContent> 
0
source

I do not know if this is what you are looking for, but it does not allow me to cache my pages.

 <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Cache-Control" CONTENT="no-store"> <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="0"> <META HTTP-EQUIV="Cache-Control" CONTENT="max-age=0"> 

I got this from an article in line that I no longer have a link.

-2
source

A terrible decision, the first command to create using adsutil will fail with error -2147024713 (0x800700B7), because the files you are trying to create already exist.

Thanks.

-3
source

Source: https://habr.com/ru/post/1276930/


All Articles