gtmetrix page speed test

 

The expiration Header are used to indicate when a particular file expires, in which case it is not loaded again if it has not yet expired and that increase your site speed and perfomance, you can check your website speeed using google page speed or gtmetrix

 

 

gtmetrix page speed

 

 

For files that are not commonly change as images, videos, javascript, stylesheets could add expiration headers thus only be charged the first time you access the page.

To do this you can use the headers: Expires containing the date on which the file expires and Cache-Control, you can add these two headers separately but if we add the Expires this will also add the Cache-Control header.

 

Expiration Using .htaccess

The Apache web servers are very versatile and can easily configure the expiration headers, for that you must include directives in the .htaccess file. In the case of the expiration ExpiresDefault it can be used for this purpose have the following directives of time: seconds, minutes, hours, days, weeks, months, years
It is recommended to place an expiration of 30 days for static files (jpg, png, gif, swf, js, css), then we could add the following code:

ExpiresActive On
ExpiresDefault A0

# Expiration of 1 month for static files

ExpiresDefault "access plus 1 months"

Furthermore expiration can also be expressed in seconds, then the example above would modifying (30 days = 60 * 60 * 24 * 30 = 2592000):

On ExpiresActive
ExpiresDefault A0

# Expiration of 1 month for static files

ExpiresDefault A2592000

Another way to add the expiration is the use of the ExpiresByType directive by which you can assign different times depending on the file type. With this directive would become the example above:


ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000

Using PHP expiration

PHP is also another solution to add headers expiration. To do this we will use the header function. The format of the header of expiration:

header ( "Expires: Mon, July 26, 2010 05:00:00 GMT");

dynamically creating the expiration using date functions would have an example with the expiration of 30 days (60 * 60 * 24 * 30 = 30 days expressed in seconds)

header ( "Cache-Control: must-revalidate");
header ( "Expires:" .gmdate ("D, d M and H: i: s"., time () + 60 * 60 * 24 * 30) "GMT");

11 COMMENTS

  1. Excellent article. Keep posting such kind of
    information on your blog. Im really impressed by your site.

    Hi there, You have performed an incredible job.
    I will certainly digg it and personally suggest to my friends.
    I’m confident they’ll be benefited from this site.

  2. I was curious if you ever considered changing the structure of your blog?

    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.

    Youve got an awful lot of text for only having 1 or 2 pictures.
    Maybe you could space it out better?

  3. I am sure this piece of writing has touched all the internet users, its really really fastidious paragraph on building up new webpage.

  4. I simply want to say I am just very new to blogging and site-building and absolutely enjoyed you’re website. Most likely I’m likely to bookmark your blog . You definitely come with awesome article content. Thanks a bunch for sharing your blog site.

  5. Thank yoou a lot for sharing this with all folks you actually know what you are spdaking approximately!

    Bookmarked. Kindly also discuss with my site =).
    We can have a link trade contract among us

  6. I’m not certain the location you’re getting your info, but good topic.
    I must spend a while learning more or understanding more.
    Thanks for great info I used to be looking for this information for my mission.

  7. Good site you may have got here.. It’s difficult to get quality writing like yours nowadays.
    I honestly appreciate individuals just like you! Be careful!!

LEAVE A REPLY

Please enter your comment!
Please enter your name here