Nachdem du cookieconsent_status nun auf die whitelist gesetzt hast, veranlasst du, dass die Seite nie aus dem Cache geladen wird, wenn das Cookie vorhanden ist.
Druckbare Version
Nachdem du cookieconsent_status nun auf die whitelist gesetzt hast, veranlasst du, dass die Seite nie aus dem Cache geladen wird, wenn das Cookie vorhanden ist.
Von der COOKIE_WHITELIST.
Ja, es funktioniert nur trotzdem nicht...
Hast du dich denn zwischenzeitlich um die veraltete .htaccess gekümmert?
Ja, sieht jetzt so aus:
Code:##
# Configs Server
##
#AddHandler php56-cgi .php
php_value memory_limit 512M
php_value max_execution_time 600
AddDefaultCharset UTF-8
php_value session.save_path /www/htdocs/w012345/tmp/
<IfModule mod_rewrite.c>
RewriteEngine On
##
# Uncomment the following lines to add "www." to the domain:
#
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Uncomment the following lines to remove "www." from the domain:
#
RewriteCond %{HTTP_HOST} ^www\.expample\.de$ [NC]
RewriteRule (.*) http://example.de/$1 [R=301,L]
#
# Make sure to replace "example.com" with your domain name.
##
##
# Set the proper MIME types
# @see https://github.com/h5bp/html5-boilerplate
##
<IfModule mod_mime.c>
AddType application/javascript js jsonp
AddType application/json json
AddType audio/ogg oga ogg
AddType audio/mp4 m4a f4a f4b
AddType video/ogg ogv
AddType video/mp4 mp4 m4v f4v f4p
AddType video/webm webm
AddType video/x-flv flv
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff woff2
AddType image/x-icon ico
AddType image/webp webp
AddType text/cache-manifest appcache manifest
AddType text/x-component htc
AddType application/xml rss atom xml rdf
AddType application/x-web-app-manifest+json webapp
AddType text/x-vcard vcf
AddType application/x-shockwave-flash swf
</IfModule>
##
# Gzip compression
# @see https://github.com/h5bp/html5-boilerplate
##
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>
##
# Expires headers (for better cache control)
# @see https://github.com/h5bp/html5-boilerplate
##
<IfModule mod_expires.c>
ExpiresActive on
##
# Productional website
##
ExpiresByType text/cache-manifest "access plus 0 seconds"
#ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
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"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
ExpiresByType text/x-component "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
#ExpiresByType text/css "access plus 1 year"
#ExpiresByType application/javascript "access plus 1 year"
##
# Disable caching during development
# @see https://github.com/contao/core/issues/4364
##
#ExpiresByType text/cache-manifest "access"
#ExpiresByType text/html "access"
#ExpiresByType text/xml "access"
#ExpiresByType application/xml "access"
#ExpiresByType application/json "access"
#ExpiresByType application/rss+xml "access"
#ExpiresByType application/atom+xml "access"
#ExpiresByType image/gif "access"
#ExpiresByType image/png "access"
#ExpiresByType image/jpeg "access"
#ExpiresByType image/x-icon "access"
#ExpiresByType video/ogg "access"
#ExpiresByType audio/ogg "access"
#ExpiresByType video/mp4 "access"
#ExpiresByType video/webm "access"
#ExpiresByType text/x-component "access"
#ExpiresByType application/x-font-ttf "access"
#ExpiresByType font/opentype "access"
#ExpiresByType application/x-font-woff "access"
#ExpiresByType image/svg+xml "access"
#ExpiresByType application/vnd.ms-fontobject "access"
#ExpiresByType text/css "access"
#ExpiresByType application/javascript "access"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_headers.c>
# Assets in /assets and /bundles either contain a hash in their filename
# or are called with a ?version suffix, therefore cache them for 1 year.
RewriteRule ^(assets|bundles)/ - [ENV=CONTAO_ASSETS:true]
Header set Cache-Control "max-age=31536000" env=CONTAO_ASSETS
# Allow CORS on the Contao TinyMCE skin.
RewriteRule ^assets/tinymce4/js/skins/contao/fonts/ - [ENV=CONTAO_TINYMCE_SKIN:true]
Header set Access-Control-Allow-Origin "*" env=CONTAO_TINYMCE_SKIN
</IfModule>
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Welchen Inhalt hat deine composer.json?
Code:{
"type": "project",
"require": {
"contao/calendar-bundle": "4.9.*",
"contao/comments-bundle": "4.9.*",
"contao/conflicts": "*@dev",
"contao/faq-bundle": "4.9.*",
"contao/listing-bundle": "4.9.*",
"contao/manager-bundle": "4.9.*",
"contao/news-bundle": "4.9.*",
"contao/newsletter-bundle": "4.9.*",
"jrgregory/m17-sticky-backend-footer": "^2.0"
},
"extra": {
"contao-component-dir": "assets"
},
"scripts": {
"post-install-cmd": [
"Contao\\ManagerBundle\\Composer\\ScriptHandler::initializeApplication"
],
"post-update-cmd": [
"Contao\\ManagerBundle\\Composer\\ScriptHandler::initializeApplication"
]
}
}
Wie sehen deine Cache Einstellungen aus? Im Response deiner Website wird nun nur der Browser Cache benutzt.Code:$ curl -I https://derastronaut.de
HTTP/2 200
date: Sat, 23 May 2020 09:39:16 GMT
server: Apache
contao-merge-cache-control: 1
cache-control: max-age=3600, private
vary: Cookie,Accept-Encoding,User-Agent
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade, strict-origin-when-cross-origin
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
contao-cache: miss
age: 0
strict-transport-security: max-age=31536000
content-length: 35257
content-type: text/html; charset=utf-8
Tja, das Problem habe ich bis heute noch nicht gelöst. Ist immer noch so, dass durch die lange Cachezeit im Shared/Public Cache eine kürzere Cachezeit für den Browser/Private Cache nur einmal funktioniert. Ist die dafür eingestellte Zeit überschritten, wird wieder vom Server bzw aus dem Shared Cache geladen, was dann aber offenbar nicht mehr mit einer neuen Cachezeit im Browsercache verbunden ist. Es wird fortan immer aus dem Shared Cache abgerufen, also vom Server. Ich habe den Private Cache mittlerweile ausgeschaltet, letztlich wirkt er sich nur noch auf Google Pagespeed aus, weil da wohl nur geprüft wird, ob ein Cachen im Browsercache grundsätzlich für eine angemessene Zeit erlaubt wird, aber in der Realität wird (nach Ablauf der ursprünglichen Browsercache-Zeit) nie mehr aus dem Browsercache geladen. Das merkt Google freilich nicht, so lang geht der Test ja nicht. Ich aktiviere den Browsercache aber nicht um Google zu gefallen (obwohl allein das natürlich schon ein Vorteil wäre aus SEO-Sicht), sondern damit die Zugriffe auf den Server weniger werden.
Ok, ich habs mittlerweile abgehakt und mich damit abgefunden. Es funktioniert halt einfach nicht so, wie ich es erwartet hatte. Was ja nicht heissen muss, dass es falsch funktioniert. So viele Zugriffe habe ich dann auch wieder nicht, dass es wirklich notwendig wäre. Mittlerweile habe ich eine weitere Baustelle entdeckt, wo ich mir wieder nicht ganz sicher bin, ob da was zu tun wäre. Es geht um Bilder und Assets. Bei den von Contao erzeugten Assets und auch Bildern wird ein max-age Response-Header zurückgegeben mit einem Wert von 365 Tagen, was dagegen direkt aus /files/... kommt, hat diesen Response-Header nicht. Muss ich morgen mal schauen, ob es dadurch auch Zugriffe auf den Server gibt für diese Original-Bilder, wenn auch wahrscheinlich nur, um das ETag zu prüfen. Dadurch, dass ETags aktiviert sind, sinkt also nicht die durch Requests erzeugte Serverlast, aber doch wenigstens der Traffic. Zum Glück betrifft das bei mir auf dieser Website auf dem Desktop nur einen relativ kleinen Bruchteil der Bilder und wohl auf den meisten Smartphones gar keine, weil die kleineren Bilder und Vorschaubilder alle von Contao erzeugt werden.
Dass das so ist, kann ich mir auch durchaus erklären. Die von Contao bearbeiteten Bilder und das CSS/JS bekommen einen Hash angehängt, der sich ändert wenn diese Dateien geändert werden. Dadurch können geänderte Dateien sowieso nicht aus dem Browsercache genommen werden und man kann deshalb den max-age Wert im Response Header ruhig auf 365 Tage setzen. Bei den Originalbildern greift die Sache mit dem Hash aber nicht, also kann man das da nicht machen, weil sonst Änderungen der Bilder erst nach 365 Tagen greifen würden. ETags werden ja nicht geprüft, wenn die Datei aus dem Browsercache genommen wird. Muss man also wohl mit leben. Ich würde das halt mittlerweile nötigenfalls mit einem leistungsfähigeren Hosting oder gleich mit einem vServer erschlagen. Oder bei der Bildgröße angeben 0.9999x anstatt 1x. :D;)
Paradoxerweise lobt mich Google Pagespeed mit
Um danach für alle 11 Ressourcen als TTL auszugeben: NoneZitat:
Uses efficient cache policy on static assets 11 resources found
A long cache lifetime can speed up repeat visits to your page. Learn more.
So ganz wissen die da wohl auch nicht immer was sie tun. Beruhigend :D. Oder halt auch nicht, wenn man bedenkt, welche Macht Google ausübt. Immerhin wird das wohl nicht ins Ranking eingehen. Denn das läuft ja alles unter der Überschrift
Wenngleich "these numbers" ;) natürlich indirekt schon durchaus den Performance Score beeinflussen können und werden.Zitat:
Diagnostics
More information about the performance of your application. These numbers don't directly affect the Performance score.
Ja, habe das nun nochmals getestet. Sobald der Age Response Header größer als max-age ist, legt der Browser nichts in den eigenen Cache ab.
Ok, wenigstens bin ich noch nicht paranoid. Aber das heisst natürlich nicht, dass SIE nicht hinter mir her sind.
Da besteht ja doch noch Hoffnung, vielleicht wird es wieder was mit dem Browsercache. Die Umwelt wird es freuen. Naja, nur wenn die Browser nicht verrückt spielen. Ich hatte jetzt tatsächlich bei einigen Versuchen den Fall (Firefox), dass die Seite hätte aus dem Browsercache genommen werden können, dann aber doch vom Server abgerufen wurde, weil der Browser das als schnellere Variante bewertet hat. Da steht dann "Raced". Der war also ernsthaft davon überzeugt, dass er die Seite vom Webserver schneller runterladen kann als er sie von meiner SSD-Festplatte lesen kann? Und selbst wenn es so wäre, gibt es ja trotzdem keinen guten Grund das zu machen. Außer wenn das einzige Ziel ist, die Seitenladezeit mit Gewalt bis auf die letzte Millisekunde zu "optimieren". Aus meiner Sicht eine Fehlentwicklung bei Firefox. Was aus dem Browsercache genommen werden kann sollte auch daraus genommen werden. Damit wird der Webserver entlastet bzw seine Kapazität kann für andere Requests genutzt werden, die nicht aus dem Browsercache des entsprechenden Browsers bedient werden können. Sei es der selbe Browser oder der eines anderen Besuchers.
Ob ein Client seinen private Cache nutzt oder nicht wirst du halt nie forcieren können.
Ist doch alles nicht so straight-forward, wie man der Symfony Diksussion entnehmen kann :D
Leider nicht! Wenn allerdings die wichtigsten Browser nach und nach alle so einen - sorry - Schwachsinn implementieren, dann können wir den private Cache eh gleich vergessen. Was nutzt es mir, wenn die Ressource im private Cache liegt und trotzdem zusätzlich ein Request an den Server gestartet wird, weil selbst eine SSD-Festplatte Firefox offenbar zu langsam ist? Nada. Im Gegenteil, da schalte ich den private Cache in meinen Browsern lieber gleich komplett aus, um wenigstens Platz auf der Festplatte zu sparen und die Lebensdauer der SSD-Festplatte zu verlängern :mad:;)
Dieses "RCWN" (Race Cache With Network) lässt sich zwar abschalten und auch konfigurieren, aber wieviele Nutzer machen das? Genau! Per Default ist es eingeschaltet und der Browser kann nach einer minimalen Wartezeit von 0(!) ms einen Request an den Server starten. Richtig toll! :( Also private Cache künftig nur noch alibimäßig für Google? Glückwunsch auch!