2012-12-20 17 views
41
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 

Quando eseguo il test del sito utilizzando yahoo YSLOW, si dice sopra il massaggio. Quindi non so come aggiungere expire headers. Un aiuto sarebbe apprezzato?Aggiungi Scade le intestazioni

+0

speranza ther sarebbe documenattion nel loro sito –

+1

Google 'php Add Scade headers' –

+0

sto supponendo che' static.doers. lk' è il tuo sito web? –

risposta

54

Il modo più semplice per aggiungere queste intestazioni è un file .htaccess che aggiunge alcune configurazioni al server. Se le risorse sono ospitate su un server che non controlli, non c'è nulla che tu possa fare al riguardo.

Nota che alcuni provider di hosting non ti permetteranno di usare i file .htaccess, quindi controlla i loro termini se non sembra funzionare.

Il progetto HTML5Boilerplate ha un eccellente file .htaccess che copre le impostazioni necessarie. Vedere la parte rilevante del file al loro Github repository

Questi sono i bit importanti

# ---------------------------------------------------------------------- 
# Expires headers (for better cache control) 
# ---------------------------------------------------------------------- 

# These are pretty far-future expires headers. 
# They assume you control versioning with filename-based cache busting 
# Additionally, consider that outdated proxies may miscache 
# www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ 

# If you don't use filenames to version, lower the CSS and JS to something like 
# "access plus 1 week". 

<IfModule mod_expires.c> 
    ExpiresActive on 

# Your document html 
    ExpiresByType text/html "access plus 0 seconds" 

# Media: images, video, audio 
    ExpiresByType audio/ogg "access plus 1 month" 
    ExpiresByType image/gif "access plus 1 month" 
    ExpiresByType image/jpeg "access plus 1 month" 
    ExpiresByType image/png "access plus 1 month" 
    ExpiresByType video/mp4 "access plus 1 month" 
    ExpiresByType video/ogg "access plus 1 month" 
    ExpiresByType video/webm "access plus 1 month" 

# CSS and JavaScript 
    ExpiresByType application/javascript "access plus 1 year" 
    ExpiresByType text/css "access plus 1 year" 
</IfModule> 

Hanno documented what that file does, il bit più importante è che è necessario rinominare il vostro file CSS e JavaScript ogni volta che cambiano, perché i browser del tuo visitatore non li ricontrollano per un anno, una volta che vengono memorizzati nella cache.

+0

voglio aggiungere quel codice completo per htaccess nel github – sami

+0

No, solo la sezione "Expires headers". O anche solo la parte che ho incollato nella mia risposta. Assicurati di aver compreso appieno cosa fa, specialmente perché [busting della cache] (https://github.com/h5bp/html5-boilerplate/blob/v4.0.2/doc/htaccess.md#cache-busting) è necessario una volta tu lo usi. – pixelistik

+0

Ho un'altra domanda. Puoi darmi una risposta? – sami

7

provare questa soluzione e si sta lavorando bene per 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 ## 
0
<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>