From 80677ef97ffb8d68c3bccc551c6dc41436b82a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 26 Feb 2024 13:21:09 +0100 Subject: [PATCH] feat: integrate with ext:static_filecache --- composer.json | 1 + composer.lock | 91 ++++++++++++++++++++++++- public/.htaccess | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5ecb912a..1cedf21e 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "kigkonsult/icalcreator": "^2.29", "league/csv": "^9.2", "league/period": "^4.9", + "lochmueller/staticfilecache": "^12.5", "ssch/typo3-encore": "^3.0", "symfony/http-client": "^4.3", "symfony/options-resolver": "^4.2", diff --git a/composer.lock b/composer.lock index ea4c0e87..083ac6f3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c893e726cae59c3033fd05e61f83cb75", + "content-hash": "25f76f1685e8ee310648c90e4c0af0f8", "packages": [ { "name": "b13/container", @@ -1771,6 +1771,95 @@ ], "time": "2022-02-21T08:41:21+00:00" }, + { + "name": "lochmueller/staticfilecache", + "version": "12.5.0", + "source": { + "type": "git", + "url": "https://github.com/lochmueller/staticfilecache.git", + "reference": "68163d7a0f1f16a1d3855b8212b8fa5682d9ae0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lochmueller/staticfilecache/zipball/68163d7a0f1f16a1d3855b8212b8fa5682d9ae0b", + "reference": "68163d7a0f1f16a1d3855b8212b8fa5682d9ae0b", + "shasum": "" + }, + "require": { + "ext-pdo": "*", + "ext-zlib": "*", + "php": "^7.4||^8.0", + "typo3/cms-core": "^10.4.21||^11.5.2", + "typo3/cms-extensionmanager": "^10.4.21||^11.5.2" + }, + "conflict": { + "tomasnorre/crawler": "<11.0.1" + }, + "replace": { + "typo3-ter/staticfilecache": "self.version" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.5", + "phpmetrics/phpmetrics": "^2.5", + "typo3/testing-framework": "^6.1" + }, + "suggest": { + "friendsofsymfony/http-cache": "For HTTP proxy cache services like Varnish", + "lochmueller/seocli": "Scan websites against SEO criteria and/or trigger the indexing process and cache warming in deployment scripts" + }, + "type": "typo3-cms-extension", + "extra": { + "typo3/cms": { + "extension-key": "staticfilecache", + "cms-package-dir": "{$vendor-dir}/typo3/cms", + "web-dir": ".Build/Web" + } + }, + "autoload": { + "psr-4": { + "SFC\\Staticfilecache\\": "Classes" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Tim Lochmüller", + "email": "tim@fruit-lab.de", + "homepage": "https://github.com/lochmueller", + "role": "Developer" + } + ], + "description": "Transparent static file cache solution using mod_rewrite and mod_expires. Increase performance for static pages by a factor of 230!!", + "homepage": "https://extensions.typo3.org/extension/staticfilecache", + "keywords": [ + "StaticFileCache", + "TYPO3 CMS", + "cache", + "file", + "magic", + "speed", + "static" + ], + "support": { + "docs": "https://docs.typo3.org/p/lochmueller/staticfilecache/main/en-us/", + "issues": "https://github.com/lochmueller/staticfilecache/issues", + "source": "https://github.com/lochmueller/staticfilecache" + }, + "funding": [ + { + "url": "https://paypal.me/lochmueller", + "type": "custom" + }, + { + "url": "https://github.com/lochmueller", + "type": "github" + } + ], + "time": "2022-08-26T13:35:21+00:00" + }, { "name": "lolli42/finediff", "version": "1.0.3", diff --git a/public/.htaccess b/public/.htaccess index bad8754c..f2387c33 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -287,6 +287,174 @@ AddDefaultCharset utf-8 RewriteCond %{REQUEST_FILENAME}\.webp -f RewriteRule ^ %{REQUEST_FILENAME}\.webp [L,T=image/webp] + + ### Begin: StaticFileCache (preparation) #### + + # Document root configuration + RewriteRule .* - [E=SFC_ROOT:%{DOCUMENT_ROOT}] + # RewriteRule .* - [E=SFC_ROOT:%{DOCUMENT_ROOT}/t3site] # Example if your installation is installed in a directory + # NOTE: There are cases (apache versions and configuration) where DOCUMENT_ROOT do not exists. Please set the SFC_ROOT to the right directory without DOCUMENT_ROOT then! + + # Cleanup URI + RewriteCond %{REQUEST_URI} ^.*$ + RewriteRule .* - [E=SFC_URI:/%{REQUEST_URI}] + RewriteCond %{REQUEST_URI} ^/.*$ + RewriteRule .* - [E=SFC_URI:%{REQUEST_URI}] + RewriteCond %{REQUEST_URI} ^/?$ + RewriteRule .* - [E=SFC_URI:/] + + # Cleanup HOST + RewriteCond %{HTTP_HOST} ^([^:]+)(:[0-9]+)?$ + RewriteRule .* - [E=SFC_HOST:%1] + + # Disable cache for EXT:solr indexing requests + RewriteCond %{HTTP:X-Tx-Solr-Iq} .+ + RewriteRule .* - [E=SFC_HOST:invalid-host] + + # Get scheme + RewriteRule .* - [E=SFC_PROTOCOL:http] + RewriteCond %{SERVER_PORT} ^443$ [OR] + RewriteCond %{HTTP:X-Forwarded-Proto} https + RewriteRule .* - [E=SFC_PROTOCOL:https] + + # Get port + RewriteRule .* - [E=SFC_PORT:80] + RewriteCond %{ENV:SFC_PROTOCOL} ^https$ [NC] + RewriteRule .* - [E=SFC_PORT:443] + RewriteCond %{SERVER_PORT} ^[0-9]+$ + RewriteRule .* - [E=SFC_PORT:%{SERVER_PORT}] + RewriteCond %{HTTP:X-Forwarded-Port} ^[0-9]+$ + RewriteRule .* - [E=SFC_PORT:%{HTTP:X-Forwarded-Port}] + + # Full path for redirect + RewriteRule .* - [E=SFC_FULLPATH:typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}_%{ENV:SFC_HOST}_%{ENV:SFC_PORT}%{ENV:SFC_URI}/index] + + # Extension (Order: br, gzip, default) + RewriteRule .* - [E=SFC_EXT:] + RewriteCond %{HTTP:Accept-Encoding} br [NC] + RewriteRule .* - [E=SFC_EXT:.br] + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT} !-f + RewriteRule .* - [E=SFC_EXT:] + RewriteCond %{ENV:SFC_EXT} ^$ + RewriteCond %{HTTP:Accept-Encoding} gzip [NC] + RewriteRule .* - [E=SFC_EXT:.gz] + RewriteCond %{ENV:SFC_EXT} ^\.gz$ + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT} !-f + RewriteRule .* - [E=SFC_EXT:] + + # Write Extension to SFC_FULLPATH + RewriteRule .* - [E=SFC_FULLPATH:%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT}] + + ### Begin: StaticFileCache (main) #### + + # We only redirect URI's without query strings + RewriteCond %{QUERY_STRING} ^$ + + # It only makes sense to do the other checks if a static file actually exists. + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} -f + + # NO frontend or backend user is logged in. Logged in users may see different + # information than anonymous users. But the anonymous version is cached. So + # don't show the anonymous version to logged in users. + RewriteCond %{HTTP_COOKIE} !staticfilecache [NC] + + # We only redirect GET requests + RewriteCond %{REQUEST_METHOD} GET + + # Rewrite the request to the static file. + RewriteRule .* %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} [L] + + # Do not allow direct call the cache entries + RewriteCond %{ENV:SFC_URI} ^/typo3temp/tx_staticfilecache/.* + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule .* - [F,L] + + # Handle application cache + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-l + RewriteRule ^.*\.sfc$ %{ENV:CWD}index.php?eID=sfc_manifest [QSA,L] + + ### Begin: StaticFileCache (options) #### + + # Set proper content type and encoding for gzipped html. + + SetEnv no-gzip 1 + SetEnv no-brotli 1 + + Header set Content-Encoding gzip + + + + SetEnv no-gzip 1 + SetEnv no-brotli 1 + + Header set Content-Encoding gzip + + + + SetEnv no-gzip 1 + SetEnv no-brotli 1 + + Header set Content-Encoding br + + + + # if there are same problems with ForceType, please try the AddType alternative + # Set proper content type gzipped html + + ForceType text/html + # AddType "text/html" .gzip + + + ForceType text/javascript + # AddType "text/javascript" .gzip + + + ForceType text/css + # AddType "text/css" .gzip + + + ForceType text/xml + # AddType "text/xml" .gzip + + + ForceType text/xml + # AddType "text/xml" .gzip + + + ForceType text/html + # AddType "text/html" .gz + + + ForceType text/xml + # AddType "text/xml" .gz + + + ForceType text/xml + # AddType "text/xml" .gz + + + ForceType text/html + # AddType "text/html" .br + + + ForceType text/xml + # AddType "text/xml" .br + + + ForceType text/xml + # AddType "text/xml" .br + + + # Avoid .br files being delivered with Content-Language: br headers + + RemoveLanguage .br + + + ### End: StaticFileCache ### + + # If the file/symlink/directory does not exist => Redirect to index.php. # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'. RewriteCond %{REQUEST_FILENAME} !-f