From 614904924f6f7c21a7f9e1aa916e5ca7f2443167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Wed, 25 Dec 2019 11:32:31 +0100 Subject: [PATCH] Include static file cache --- composer.json | 1 + composer.lock | 83 ++++++++++++++++++++++++- public/.htaccess | 156 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 614c0597..b8af5bf6 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "kigkonsult/icalcreator": "^2.29", "league/csv": "^9.2", "league/period": "^4.9", + "lochmueller/staticfilecache": "^10.2", "pixelant/pxa-social-feed": "^2.0", "symfony/http-client": "^4.3", "symfony/options-resolver": "^4.2", diff --git a/composer.lock b/composer.lock index 6d885a5d..07a445ae 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": "3c9082df3930a24daad45b684ce6c58a", + "content-hash": "8d24d6aa5cf407f4ae9811bc6a781623", "packages": [ { "name": "algo26-matthias/idna-convert", @@ -1197,9 +1197,9 @@ "authors": [ { "name": "Helmut Hummel", - "role": "Developer", "email": "info@helhum.io", - "homepage": "http://helhum.io" + "homepage": "http://helhum.io", + "role": "Developer" } ], "description": "A reliable and powerful command line interface for TYPO3 CMS", @@ -1476,6 +1476,83 @@ ], "time": "2019-09-02T06:27:10+00:00" }, + { + "name": "lochmueller/staticfilecache", + "version": "10.2.1", + "source": { + "type": "git", + "url": "https://github.com/lochmueller/staticfilecache.git", + "reference": "63dc21dabc1a7dc226045c460ffa77134506a43e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lochmueller/staticfilecache/zipball/63dc21dabc1a7dc226045c460ffa77134506a43e", + "reference": "63dc21dabc1a7dc226045c460ffa77134506a43e", + "shasum": "" + }, + "require": { + "ext-pdo": "*", + "ext-zlib": "*", + "php": "^7.2||^7.3", + "typo3/cms-core": "^9.5||^10.2", + "typo3/cms-extbase": "^9.5||^10.2", + "typo3/cms-frontend": "^9.5||^10.2" + }, + "replace": { + "typo3-ter/staticfilecache": "self.version" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.14", + "namelesscoder/typo3-repository-client": "^2.0", + "phpmd/phpmd": "^2.6", + "phpmetrics/phpmetrics": "^2.4", + "rector/rector": "^0.4", + "scrutinizer/ocular": "^1.5", + "squizlabs/php_codesniffer": "^3.4", + "typo3/testing-framework": "^4.2" + }, + "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 StaticFileCache solution using mod_rewrite and mod_expires. Increase performance for static pages by a factor of 230!!", + "homepage": "https://github.com/lochmueller/staticfilecache", + "keywords": [ + "StaticFileCache", + "TYPO3 CMS", + "cache", + "file", + "magic", + "speed", + "static" + ], + "time": "2019-12-09T08:17:21+00:00" + }, { "name": "nikic/php-parser", "version": "v4.3.0", diff --git a/public/.htaccess b/public/.htaccess index 71fc4732..c78f5b06 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -292,6 +292,162 @@ AddDefaultCharset utf-8 # NOTE: Add your additional local storages here RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L] + ### Begin: StaticFileCache (preparation) #### + + # Document root configuration + RewriteRule .* - [E=SFC_ROOT:%{DOCUMENT_ROOT}] + + # 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/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