2016-04-20 21 views
8

Sto utilizzando le informazioni sulla velocità della pagina di Google per migliorare le prestazioni, ma non importa quello che faccio Non riesco a ottenere la funzione di "sfruttare il caching del browser" per scomparire.Sfrutta il caching del browser - gli aggiornamenti non funzionano

Ho modificato il file htaccess come descritto in diversi articoli online e ho aggiunto ogni combinazione possibile. Nelle informazioni di pagina si lamenta dei file CSS/PNG/JS/JPG.

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

risposta

6

Sembra che manchi più in "accesso più 1 mese" in molte righe. di default dovrebbe essere la vostra seconda linea per migliorare la leggibilità

Ecco parte del modello h5bp:

ExpiresActive on 
ExpiresDefault          "access plus 1 month" 
ExpiresByType text/css        "access plus 1 year" 
ExpiresByType text/html        "access plus 0 seconds" 
ExpiresByType application/javascript    "access plus 1 year" 
ExpiresByType application/x-javascript    "access plus 1 year" 
ExpiresByType text/javascript      "access plus 1 year" 

... https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

5

Se stai usando Apache, si potrebbe desiderare di eseguire questi come questo ha funzionato per me:

sudo a2enmod headers 
sudo a2enmod expires 
service apache2 restart 

Si potrebbe anche voler provare questo codice:

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

Quel codice non sembra molto diverso da quello che ho già. – connersz

+0

@connersz Hai provato a eseguire i comandi? – Edward

0

Forse provare questo:

# 1 Month for most static assets 
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$"> 
Header set Cache-Control "max-age=2592000, public" 
</filesMatch> 
Problemi correlati