• July 12, 2017

    ExpiresActive On ExpiresByType image/gif A2592000

    ให้เก็บภาพ gif Cache ไว้ 30 วัน
    ใน 30 วัน, web browser จะไม่เรียกไฟล์นี้ซ้ำจาก Server ใหม่
    แต่จะเรียกจาก Cache ของ Web Browser เอง ทำให้การโหลดเร็วขึ้น

    Please create or modify your .htaccess file and add this line

    ExpiresActive On

    Or

    # Expire images header
    ExpiresActive On
    ExpiresDefault A0
    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType text/css A2592000

    How to Add Expires Headers

    First you need to decide on what files you update often and what file types don’t get updated often. A common list of file types we see a lot are:

    images: jpg, gif, png
    favicon/ico
    javascript
    css
    Now go through these file types and think how often you change each one. Commonly images typically are not changed too often (keep in mind we are talking about existing images) favicon is almost never changed, javascript is occasionally changed and CSS is change much more frequently.

    We define our Expires Headers in the .htaccess file. This is a hidden file often found in the root of your website (via FTP). It’s always best practice before you edit the htaccess file to back it up!

    Now, open up your htaccess file and paste in the following:

    <IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 
    # Default directive
    ExpiresDefault "access plus 1 month"
    </IfModule>

    First we enable expirations and then we set a default expiry date for files we don’t specify. Now we want to add the lines to explain what expires when. Right above the paste the following and change the dates to reflect the times that best suit your website.

    # 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"

    Your complete file should look like:

    # 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"

    Optimize your WordPress Site for SEO and Reduce your Bounce Rates.

    a little snippet to add in your .htaccess file that will set your Expire Headers time.

    The faster your site loads the better is for your SEO and for your Bounce Rates.

    Expire Headers is letting your browser to cache your website content and request them only after the time specified in that rule expires.

    If you want to set Expire Headers for all of your image,js and css file you have to open and edit your .htaccess file and the following rule:

    <FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css|woff)$">
    ExpiresActive On
    ExpiresDefault A2592000

    FilesMatch sets the file extensions that are affected by the ExpiresActive rule while the ExpiresDefault sets the cache time, when that time expires then your website visitor browser will request once more the files.

    ExpiresDefault is access time (A) plus 30 days (2592000 seconds), so using the same rule you can set your own ExpiresDefault time(just be careful to calculate in seconds).

    If you want to set a separate Expire Headers rule for each of your filetypes then you can use the following snippet on your .htaccess.

    ExpiresByType image/png A2592000
    ExpiresByType image/gif A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType text/javascript A2592000
    ExpiresByType application/x-javascript A2592000
    ExpiresByType text/css A2592000


เวอไนน์ไอคอร์ส

ประหยัดเวลากว่า 100 เท่า!






เวอไนน์เว็บไซต์⚡️
สร้างเว็บไซต์ ดูแลเว็บไซต์

Categories