[html] Add Expires headers

Add Expires headers
There are 21 static components without a far-future expiration date.

    http://static.doers.lk/examples-offline.css
    http://static.doers.lk/kendo.common.min.css
    http://static.doers.lk/kendo.default.min.css
    http://static.doers.lk/style.css
    http://static.doers.lk/jquery.min.js
    http://static.doers.lk/kendo.web.min.js
    http://static.doers.lk/console.js
    http://static.doers.lk/sprite.png
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    http://static.doers.lk/favicon.PNG

When testing the site using yahoo YSLOW it says above message. So I don't know how to add expire headers. Any help would be appreciated?

This question is related to html yslow expires-header

The answer is


try this solution and it is working fine for me

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/x-js text/js 
</IfModule>

## EXPIRES CACHING ##

<IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 

    # Default directive
    ExpiresDefault "access plus 1 month"

    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"

    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"

    # CSS
    ExpiresByType text/css "access plus 1 month"

    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>

You can add them in your htaccess file or vhost configuration.

See here : http://httpd.apache.org/docs/2.2/mod/mod_expires.html

But unless you own those domains .. they are our of your control.


In ASP.NET there is similar object, you can use Caching Portions in WebFormsUserControls in order to cache objects of a page for a period of time and save server resources. This is also known as fragment caching.
If you include this code to top of your user control, a version of the control stored in the output cache for 150 seconds. You can create your own control that would contain expire header for a specific resource you want.

<%@ OutputCache Duration="150" VaryByParam="None" %>

This article explain it completely: Caching Portions of an ASP.NET Page