2016-04-20 93 views
8

Performansı iyileştirmek için Google sayfa hız bilgisini kullanıyorum ancak ne yaparsam yap bilmiyorum 'kaldıraç tarayıcısını önbelleğe alma' özelliğini kullanamıyorum.Tarayıcı önbellekleme özelliğinden yararlanın - çalışma başlatılmıyor

Birkaç çevrimiçi makalede anlatıldığı gibi htaccess dosyasını değiştirdim ve yapabildiğim her bileşimi ekledim. Sayfa içi analizlerde CSS/PNG/JS/JPG dosyaları hakkında şikayette bulunuyor.

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

cevap

6

Size birçok satırda "erişim artı 1 ay" içinde eksik görünüyorsunuz. Standart okunabilmesi için ikinci satır olmalıdır

İşte

h5bp şablonunun parçasıdır:

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" 

... Apache kullanıyorsanız https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

5

, bu çalıştırmak isteyebilirsiniz Bu benim için çalıştı gibidir:

sudo a2enmod headers 
sudo a2enmod expires 
service apache2 restart 

Ayrıca bu kodu denemek isteyebilirsiniz:

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

Bu kod zaten ne var çok farklı görünmüyor. – connersz

+0

@connersz Komutları çalıştırmayı denediniz mi? – Edward

0

Belki bu deneyin:

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