Google PageSpeed sagte Browser-Caching nutzen

Hallo Piwik-Freunde,
wenn ich Google PageSpeed mache, dann meckert Google:

Browser-Caching nutzen
das Festlegen eines Ablaufdatums oder eines Höchstalters in den HTTP-Headern für statische Ressourcen weist den Browser an, zuvor heruntergeladene Ressourcen über die lokale Festplatte anstatt über das Netzwerk zu laden.

Wie kann man das ändern das und ein Ablaufdatum festlegen kann damit Google nicht mehr meckern kann.

Danke für Tipps.

LG
MaWi

Hi

sofern du PageSpeed nicht direkt auf dein Piwik angesetzt hast (was quatsch wäre), hat das nichts mit Piwik zu tun.

Um Google zufrieden zu stellen, musst du diverse HTTP-Header ‘richtig’ einstellen. Die wichtigsten HTTP-Header in dem Zusammenhang heißen Cache-Control, Expires und E-Tag. Wie man das eisntellen kann geht, hängt ganz von deiner Software (Website-/Blogsystem, Webserver, Programmiersprache) ab. Da solltest du in den entsprechenden Foren nachschauen.

Exakte Informationen findest du hier.

Für etwas einfacherer Kost, frag Google nach z.B. “Wordpress Cache-Control” (wenn du z.B. Wordpress verwendest.)

Hallo GatheredPain,

vielen Dank für Deine Antwort.
Benutze Wordpress als System, und habe den Code in den Footer gepackt von Piwik.

Der Cache an sich an läuft laut Google Page Speed, nur das Google über Piwik meckert.

Danke Dir für den Google Tipp werde noch einmal schauen, falls jemand noch eine Idee ob ich was in die .htaccess von Wordpress einfügen kann damit Google Happy ist gerne her damit.

LG
MaWi

Wenn du Piwik mit dem Standardmäßigen Code einbindest, sollte PageSpeed das eigentlich nicht stören.

Verrat doch mal die URL, dann kann man nachschauen, was da ggf. nicht stimmt.

Langt Dir an sich der Code?
Ist halt in der footer.php ganz unten eingebunden:
*************************************



Vielleicht Hilft es Dir ja so erstmal??

Danke für einen Tipp, Piwik liegt bei mir auf einer Sub-Domain und läuft unter https.

Hat jemand noch eine Idee?

Je nachdem wie der Webserver deines Providers eingerichtet ist, sind die Ablaufzeiten schon voreingestellt. Meistens lässt sich das mit Hilfe der .htaccess selbst beeinflussen.

Schau mal in das Hauptverzeichnis deines Webspaces. (Gegebenenfalls musst du im FTP-Programm einstellen, dass dir auch versteckte Dateien angezeigt werden sollen.)
Versuch mal folgende Zeilen in der .htaccess zu ergänzen:

# Gzip
<IfModule mod_mime.c>
	AddType text/javascript                js
	AddType application/vnd.ms-fontobject  eot
	AddType font/ttf                       ttf
	AddType font/otf                       otf
	AddType font/x-woff                    woff
	AddType image/svg+xml                  svg 
	AddType image/svg+xml                  svgz
	AddEncoding gzip                       svgz
</Ifmodule>

# Ablaufzeiten festlegen
<IfModule mod_expires.c>
	ExpiresActive on
	ExpiresDefault "access plus 5 minutes"
	ExpiresByType image/ico "access plus 1 year"
	ExpiresByType image/jpg "access plus 1 month"
	ExpiresByType image/jpeg "access plus 1 month"
	ExpiresByType image/gif "access plus 1 month"
	ExpiresByType image/png "access plus 1 month"
	ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
	ExpiresByType font/ttf "access plus 1 month"
	ExpiresByType font/otf "access plus 1 month"
	ExpiresByType font/x-woff "access plus 1 month"
	ExpiresByType image/svg+xml "access plus 1 month"
	ExpiresByType application/x-shockwave-flash "access plus 1 month"
	ExpiresByType text/html "access plus 4 hours"
	ExpiresByType text/htm "access plus 4 hours"
	ExpiresByType text/javascript "access plus 7 days"
	ExpiresByType text/css "access plus 7 days"
	ExpiresByType text/xml "access plus 7 days"
	ExpiresByType application/xml "access plus 0 seconds"
	ExpiresByType application/json "access plus 0 seconds"
	ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>


# Komprimierung aktivieren
<IfModule mod_headers.c>
	AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript
	AddOutputFilterByType DEFLATE application/xml
	AddOutputFilterByType DEFLATE application/rss+xml
	AddOutputFilterByType DEFLATE application/javascript application/x-javascript

# Ausnahmen
	BrowserMatch ^Mozilla/4\.0[678] no-gzip
	BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
</IfModule>

Hallo Top,

vielen Dank für Deine Nachricht, in meiner .htaccess steht folgendes bereits drinnen:

# verhindert das Auslesen eines Autoren-Namen
RewriteCond %{QUERY_STRING} .*author=(.+.?) [NC]
RewriteRule (.*) /? [NC,L,R=301]

<Files wp-login.php>
AuthName "Schloss"
AuthType Basic
AuthUserFile /var/www/vhosts/xxxxxx.de/httpdocs/.htpasswd
Require valid-user
</Files>

# ----------------------------------------------------------------------
# | Komprimierung und Caching                                                    |
# ----------------------------------------------------------------------

<IfModule mod_expires.c>

    ExpiresActive on
    ExpiresDefault                                      "access plus 1 month"

  # CSS

    ExpiresByType text/css                              "access plus 1 year"


  # Data interchange

    ExpiresByType application/atom+xml                  "access plus 1 hour"
    ExpiresByType application/rdf+xml                   "access plus 1 hour"
    ExpiresByType application/rss+xml                   "access plus 1 hour"

    ExpiresByType application/json                      "access plus 0 seconds"
    ExpiresByType application/ld+json                   "access plus 0 seconds"
    ExpiresByType application/schema+json               "access plus 0 seconds"
    ExpiresByType application/vnd.geo+json              "access plus 0 seconds"
    ExpiresByType application/xml                       "access plus 0 seconds"
    ExpiresByType text/xml                              "access plus 0 seconds"


  # Favicon (cannot be renamed!) and cursor images

    ExpiresByType image/vnd.microsoft.icon              "access plus 1 week"
    ExpiresByType image/x-icon                          "access plus 1 week"

  # HTML

    ExpiresByType text/html                             "access plus 3600 seconds"


  # JavaScript

    ExpiresByType application/javascript                "access plus 1 year"
    ExpiresByType application/x-javascript              "access plus 1 year"
    ExpiresByType text/javascript                       "access plus 1 year"


  # Manifest files

    ExpiresByType application/manifest+json             "access plus 1 week"
    ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
    ExpiresByType text/cache-manifest                   "access plus 0 seconds"


  # Media files

    ExpiresByType audio/ogg                             "access plus 1 month"
    ExpiresByType image/bmp                             "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 image/svg+xml                         "access plus 1 month"
    ExpiresByType image/webp                            "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"


  # Web fonts

    # Embedded OpenType (EOT)
    ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
    ExpiresByType font/eot                              "access plus 1 month"

    # OpenType
    ExpiresByType font/opentype                         "access plus 1 month"

    # TrueType
    ExpiresByType application/x-font-ttf                "access plus 1 month"

    # Web Open Font Format (WOFF) 1.0
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/x-font-woff               "access plus 1 month"
    ExpiresByType font/woff                             "access plus 1 month"

    # Web Open Font Format (WOFF) 2.0
    ExpiresByType application/font-woff2                "access plus 1 month"


  # Other

    ExpiresByType text/x-cross-domain-policy            "access plus 1 week"

</IfModule>

<IfModule mod_deflate.c>
# Insert filters / compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/vtt 
AddOutputFilterByType DEFLATE text/x-component
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/js
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/atom+xml 
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/ld+json 
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
AddOutputFilterByType DEFLATE application/x-font-ttf 
AddOutputFilterByType DEFLATE application/x-web-app-manifest+json 
AddOutputFilterByType DEFLATE font/opentype 
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon 

# Exception: Images
SetEnvIfNoCase REQUEST_URI \.(?:gif|jpg|jpeg|png|svg)$ no-gzip dont-vary

# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

#Alternative caching using Apache's "mod_headers", if it's installed.
#Caching of common files - ENABLED
<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|swf|js|css|gif|png|jpg|jpeg|txt)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

# Set Keep Alive Header
<IfModule mod_headers.c>
    Header set Connection keep-alive
</IfModule>

# If your server don't support ETags deactivate with "None" (and remove header)
<IfModule mod_expires.c> 
  <IfModule mod_headers.c> 
    Header unset ETag 
  </IfModule> 
  FileETag None 
</IfModule>

# ----------------------------------------------------------------------
# | 6g Firewall für Sicherheit
# ----------------------------------------------------------------------

# 6G FIREWALL/BLACKLIST
# @ https://perishablepress.com/6g/

# 6G:[QUERY STRINGS]
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{QUERY_STRING} (eval\() [NC,OR]
	RewriteCond %{QUERY_STRING} (127\.0\.0\.1) [NC,OR]
	RewriteCond %{QUERY_STRING} ([a-z0-9]{2000}) [NC,OR]
	RewriteCond %{QUERY_STRING} (javascript:)(.*)(;) [NC,OR]
	RewriteCond %{QUERY_STRING} (base64_encode)(.*)(\() [NC,OR]
	RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC,OR]
	RewriteCond %{QUERY_STRING} (<|%3C)(.*)script(.*)(>|%3) [NC,OR]
	RewriteCond %{QUERY_STRING} (\\|\.\.\.|\.\./|~|`|<|>|\|) [NC,OR]
	RewriteCond %{QUERY_STRING} (boot\.ini|etc/passwd|self/environ) [NC,OR]
	RewriteCond %{QUERY_STRING} (thumbs?(_editor|open)?|tim(thumb)?)\.php [NC,OR]
	RewriteCond %{QUERY_STRING} (\'|\")(.*)(drop|insert|md5|select|union) [NC]
	RewriteRule .* - [F]
</IfModule>

# 6G:[REQUEST METHOD]
<IfModule mod_rewrite.c>
	RewriteCond %{REQUEST_METHOD} ^(connect|debug|delete|move|put|trace|track) [NC]
	RewriteRule .* - [F]
</IfModule>

# 6G:[REFERRERS]
<IfModule mod_rewrite.c>
	RewriteCond %{HTTP_REFERER} ([a-z0-9]{2000}) [NC,OR]
	RewriteCond %{HTTP_REFERER} (semalt.com|todaperfeita) [NC]
	RewriteRule .* - [F]
</IfModule>

# 6G:[REQUEST STRINGS]
<IfModule mod_alias.c>
	RedirectMatch 403 (?i)([a-z0-9]{2000})
	RedirectMatch 403 (?i)(https?|ftp|php):/
	RedirectMatch 403 (?i)(base64_encode)(.*)(\()
	RedirectMatch 403 (?i)(=\\\'|=\\%27|/\\\'/?)\.
	RedirectMatch 403 (?i)/(\$(\&)?|\*|\"|\.|,|&|&amp;?)/?$
	RedirectMatch 403 (?i)(\{0\}|\(/\(|\.\.\.|\+\+\+|\\\"\\\")
	RedirectMatch 403 (?i)(~|`|<|>|:|;|,|%|\\|\s|\{|\}|\[|\]|\|)
	RedirectMatch 403 (?i)/(=|\$&|_mm|cgi-|etc/passwd|muieblack)
	RedirectMatch 403 (?i)(&pws=0|_vti_|\(null\)|\{\$itemURL\}|echo(.*)kae|etc/passwd|eval\(|self/environ)
	RedirectMatch 403 (?i)\.(aspx?|bash|bak?|cfg|cgi|dll|exe|git|hg|ini|jsp|log|mdb|out|sql|svn|swp|tar|rar|rdf)$
	RedirectMatch 403 (?i)/(^$|(wp-)?config|mobiquo|phpinfo|shell|sqlpatch|thumb|thumb_editor|thumbopen|timthumb|webshell)\.php
</IfModule>

# 6G:[USER AGENTS]
<IfModule mod_setenvif.c>
	SetEnvIfNoCase User-Agent ([a-z0-9]{2000}) bad_bot
	SetEnvIfNoCase User-Agent (archive.org|binlar|casper|checkpriv|choppy|clshttp|cmsworld|diavol|dotbot|extract|feedfinder|flicky|g00g1e|harvest|heritrix|httrack|kmccrew|loader|miner|nikto|nutch|planetwork|postrank|purebot|pycurl|python|seekerspider|siclab|skygrid|sqlmap|sucker|turnit|vikspider|winhttp|xxxyy|youda|zmeu|zune) bad_bot
	<limit GET POST PUT>
		Order Allow,Deny
		Allow from All
		Deny from env=bad_bot
	</limit>
</IfModule>

# 6G:[BAD IPS]
<Limit GET HEAD OPTIONS POST PUT>
	Order Allow,Deny
	Allow from All
	# uncomment/edit/repeat next line to block IPs
	# Deny from 123.456.789
</Limit>

# ----------------------------------------------------------------------
#   Wichtige WordPress-Dateien gegen den Zugriff von außen blocken
# ----------------------------------------------------------------------	

# Kein Zugriff auf die install.php
<files install.php>
Order allow,deny
Deny from all
</files>
 
# Kein Zugriff auf die wp-config.php 
<files wp-config.php>
Order allow,deny
Deny from all
</files>
 
# Kein Zugriff auf das Error-Log 
<files error_log>
Order allow,deny
Deny from all
</files>

#Zugriff auf .htaccess und .htpasswd verbieten. Wenn keine .htpasswd benutzt wird, kann der Code dafür entfernt werden.
<FilesMatch "(\.htaccess|\.htpasswd)">
  Order deny,allow
  Deny from all
</FilesMatch>

# Den Zugriff auf den Include-Ordner verbieten
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>

 
 # XML-RPC Schnittstelle komplett abschalten
<Files xmlrpc.php>
 Order Deny,Allow
 Deny from all
 </Files>


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Dann musst du mal bei der Meldung von PageSpeed schauen welche Datei(-Endungen) dort angemeckert werden und die entsprechenden Dateiendungen in der .htaccess ergänzen.

Und vorher zur Sicherheit eine Kopie erstellen! :wink:

Hallo Top,

vielen Dank für Deine Antwort.
Dieses meckert Google an :wink:
https://xxx.xxxx.de/piwik.js

Kannst Du mir eventuell sagen wie ich das ergänzen würde in der .htaccees z.b. in Deinem Code den Du geliefert hast :grinning:
Danke Dir für einen Tipp :slight_smile:

So der Experte bin ich da leider auch nicht.

Ich würde mal versuchen den Bereich für JavaScript folgendermaßen zu ergänzen:

# JavaScript

AddType text/javascript                js

ExpiresByType application/javascript                "access plus 1 year"
ExpiresByType application/x-javascript              "access plus 1 year"
ExpiresByType text/javascript                       "access plus 1 year"

Keine Ahnung ob das schon reicht oder ob es danach überhaupt noch funktionuckelt. :confused:

So etwas hatte ich schon einmal im Code:

` # JavaScript

ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/javascript “access plus 1 year”`

Hatte nichts gebracht!

Das hatte ich gesehen.
Ergänze dort mal testweise die Zeile die ich dazwischen geschrieben habe. Ich gehe davon aus, dass die Reihenfolge hier wichtig ist und habe dir daher nicht nur die einzelne Zeile gegeben.

Hm so:

`

ExpiresActive on
ExpiresDefault "access plus 5 minutes"
ExpiresByType image/ico "access plus 1 year"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType font/ttf "access plus 1 month"
ExpiresByType font/otf "access plus 1 month"
ExpiresByType font/x-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/html "access plus 4 hours"
ExpiresByType text/htm "access plus 4 hours"
ExpiresByType text/javascript "access plus 7 days"
ExpiresByType text/css "access plus 7 days"
ExpiresByType text/xml "access plus 7 days"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType text/cache-manifest "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”

Komprimierung aktivieren

AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript application/x-javascript

Ausnahmen

BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
`

Ich meinte diese Zeile ergänzen:

AddType text/javascript                js

und das auch bevor du mit ExpireByType die Ablaufzeit für text/javascript festlegst.

Meinst Du so?

Gzip

AddType text/javascript js AddType application/vnd.ms-fontobject eot AddType font/ttf ttf AddType font/otf otf AddType font/x-woff woff AddType image/svg+xml svg AddType image/svg+xml svgz AddEncoding gzip svgz

JavaScript

AddType text/javascript js

ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/javascript “access plus 1 year”

Ablaufzeiten festlegen

ExpiresActive on ExpiresDefault "access plus 5 minutes" ExpiresByType image/ico "access plus 1 year" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType image/gif "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType application/vnd.ms-fontobject "access plus 1 month" ExpiresByType font/ttf "access plus 1 month" ExpiresByType font/otf "access plus 1 month" ExpiresByType font/x-woff "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" ExpiresByType text/html "access plus 4 hours" ExpiresByType text/htm "access plus 4 hours" ExpiresByType text/javascript "access plus 7 days" ExpiresByType text/css "access plus 7 days" ExpiresByType text/xml "access plus 7 days" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType application/json "access plus 0 seconds" ExpiresByType text/cache-manifest "access plus 0 seconds"

Komprimierung aktivieren

AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript application/x-javascript

Ausnahmen

BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html

Nein.
Ich meinte, dass du nur die eine Zeile mit in deine bestehende .htaccess einfügst. Und damit du es auch an die richtige Stelle setzt, habe ich den entsprechenden Absatz von dir dazu geschrieben.

Habe das gefunden gehabt gestern Nacht:

Hat an sich geklappt.