From cc1bf5d4263bf80c190fe6c01ca2f16c3d66ee47 Mon Sep 17 00:00:00 2001 From: tinect Date: Sun, 20 Oct 2019 21:25:58 +0200 Subject: [PATCH] deliver CSS and JS as external request --- data/conf/nginx/includes/site-defaults.conf | 6 ++++- data/web/inc/footer.inc.php | 19 +++++++------- data/web/inc/header.inc.php | 17 ++++++------- data/web/resource.php | 28 +++++++++++++++++++++ 4 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 data/web/resource.php diff --git a/data/conf/nginx/includes/site-defaults.conf b/data/conf/nginx/includes/site-defaults.conf index 53778020..3de4c1a2 100644 --- a/data/conf/nginx/includes/site-defaults.conf +++ b/data/conf/nginx/includes/site-defaults.conf @@ -32,7 +32,7 @@ gzip_buffers 16 8k; gzip_http_version 1.1; gzip_min_length 256; - gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon; location ~ ^/(fonts|js|css|img)/ { expires max; @@ -205,3 +205,7 @@ location @awaitingupstream { rewrite ^(.*)$ /_status.502.html break; } + + location ~ ^/cache/(.*)$ { + try_files $uri $uri/ /resource.php?file=$1; + } diff --git a/data/web/inc/footer.inc.php b/data/web/inc/footer.inc.php index 1d9f5c44..9fec2b69 100644 --- a/data/web/inc/footer.inc.php +++ b/data/web/inc/footer.inc.php @@ -3,15 +3,16 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php'; logger(); ?>
- + +getDataHash(); +$JSPath = '/tmp/' . $hash . '.js'; +if(!file_exists($JSPath)) { + $js_minifier->minify($JSPath); + cleanupJS($hash); +} +?> +