2016-12-06 3 views
1

Ich bin mit Laravel 5, für die Geschwindigkeit Ich teste in Einblick google Geschwindigkeit, seine zeigt Hebel Browser-CachingHebel Browser-Caching .htaccess funktioniert nicht

zu lösen, dass ich folgende .htaccess-Code verwendet haben, aber nicht von ihnen arbeiten

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteRule ^(.*)$ public/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA] 
</IfModule> 

<IfModule mod_headers.c> 
# Serve gzip compressed CSS files if they exist 
# and the client accepts gzip. 
RewriteCond "%{HTTP:Accept-encoding}" "gzip" 
RewriteCond "%{REQUEST_FILENAME}\.gz" -s 
RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA] 

# Serve gzip compressed JS files if they exist 
# and the client accepts gzip. 
RewriteCond "%{HTTP:Accept-encoding}" "gzip" 
RewriteCond "%{REQUEST_FILENAME}\.gz" -s 
RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA] 


# Serve correct content types, and prevent mod_deflate double gzip. 
RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1] 
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1] 


<FilesMatch "(\.js\.gz|\.css\.gz)$"> 
    # Serve correct encoding type. 
    Header append Content-Encoding gzip 

    # Force proxies to cache gzipped & 
    # non-gzipped css/js files separately. 
    Header append Vary Accept-Encoding 
</FilesMatch> 
</IfModule> 

<IfModule mod_expires.c> 
ExpiresActive on 

# Perhaps better to whitelist expires rules? Perhaps. 
ExpiresDefault "access plus 1 month" 

# Media: images, video, audio 
ExpiresByType assets/images "access plus 1 month" 

# CSS and JavaScript 
ExpiresByType assets/css "access plus 1 month" 
ExpiresByType assets/js "access plus 1 month" 

<IfModule mod_headers.c> 
Header append Cache-Control "public" 
</IfModule> 

</IfModule> 

zweiter Code, den ich in .htaccess verwendet wird, ist dies einen

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteRule ^(.*)$ public/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA] 
</IfModule> 
<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresDefault "access plus 1 year" 
ExpiresByType text/html "access plus 1 second" 
ExpiresByType image/gif "access plus 2592000 seconds" 
ExpiresByType image/jpeg "access plus 2592000 seconds" 
ExpiresByType image/png "access plus 2592000 seconds" 
ExpiresByType image/x-icon "access plus 2592000 seconds" 
ExpiresByType text/css "access plus 604800 seconds" 
ExpiresByType text/javascript "access plus 604800 seconds" 
ExpiresByType application/x-javascript "access plus 604800 seconds" 
</IfModule> 

ich diesen Code in .htaccess auch versucht, damit es funktioniert, aber diese auch nicht funktioniert

<IfModule mod_expires.c> 
# Set Cache-Control and Expires headers 
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$"> 
Header set Cache-Control "max-age=2592000, public" 
Header set Expires "1 day" 
</filesMatch> 
<filesMatch "\\.(css|css.gz)$"> 
Header set Cache-Control "max-age=604800, public" 
</filesMatch> 
<filesMatch "\\.(js|js.gz)$"> 
Header set Cache-Control "max-age=604800, public" 
</filesMatch> 
<filesMatch "\\.(xml|txt)$"> 
Header set Cache-Control "max-age=216000, public, must-revalidate" 
</filesMatch> 
<filesMatch "\\.(html|htm)$"> 
Header set Cache-Control "max-age=7200, public, must-revalidate" 
</filesMatch> 
</IfModule> 

Ich habe all oben genannten Code verwendet, aber ich habe gleiches Ergebnis jedes Mal beheben soll: Leverage Browser-Caching

auf dem größten Teil des anaylser.

ist alles, was ich in diesem

+0

Es kann Caching-Header auf Ihrem html erwarten, aber das wird nicht wirklich Ihre Geschwindigkeit zu verbessern, ohne vorab generierte Inhalte dient. Außerdem erwarten die ersten und dritten Regelwerke, dass Sie vorkomprimiertes JS und CSS bereitstellen. – Walf

Antwort

1

prüfen bin fehlen, die Module in Server aktivieren sind.

Wenn Module nicht aktiviert sind, funktioniert der Code nicht.

1

Wenn Sie in Ubuntu versuchen diese

sudo a2enmod expires 
sudo systemctl restart apache2 
+0

danke seine helpls mich :) – viji