From ec95dd532ae018231163de0c5d5cae0a02f69039 Mon Sep 17 00:00:00 2001 From: chenyh Date: Sun, 12 Jun 2022 19:46:55 +0800 Subject: [PATCH] feat: Global performance improve add no-cache for html --- .../generators/conf/general.conf.js | 12 ++++++ .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 5 ++- .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.js | 2 + .../templates/global_sections/performance.vue | 43 +++++++++++-------- .../util/angular_backwards_compatibility.js | 1 + src/nginxconfig/util/types_extensions.js | 1 + 13 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/nginxconfig/generators/conf/general.conf.js b/src/nginxconfig/generators/conf/general.conf.js index 52b5d69..3a024cb 100644 --- a/src/nginxconfig/generators/conf/general.conf.js +++ b/src/nginxconfig/generators/conf/general.conf.js @@ -41,6 +41,17 @@ export default (domains, global) => { }; if (global.logging.accessLog.computed) config['location = /robots.txt'].access_log = 'off'; + if (global.performance.changesTakeEffect.computed) { + // Take effect in time for html + config['# Take effect in time for html'] = ''; + const loc = `location ~* \\.(?:${extensions.html})$`; + config[loc] = { + add_header: 'Cache-Control "no-cache"', + }; + if (global.logging.accessLog.computed) config[loc].access_log = 'off'; + } + + if (domains.every(d => d.routing.root.computed)) { if (global.performance.assetsExpiration.computed === global.performance.mediaExpiration.computed) { if (global.performance.assetsExpiration.computed) { @@ -124,6 +135,7 @@ export default (domains, global) => { config.brotli_types = gzipTypes; } + // Done! return config; }; diff --git a/src/nginxconfig/i18n/de/templates/global_sections/performance.js b/src/nginxconfig/i18n/de/templates/global_sections/performance.js index 808c8db..d43b201 100644 --- a/src/nginxconfig/i18n/de/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/de/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Gzip Komprimierung', enableGzipCompression: `${common.enable} Gzip Komprimierung`, brotliCompression: 'Brotli Komprimierung', diff --git a/src/nginxconfig/i18n/en/templates/global_sections/performance.js b/src/nginxconfig/i18n/en/templates/global_sections/performance.js index 5e2e3a4..200ff98 100644 --- a/src/nginxconfig/i18n/en/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/en/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Gzip compression', enableGzipCompression: `${common.enable} gzip compression`, brotliCompression: 'Brotli compression', diff --git a/src/nginxconfig/i18n/es/templates/global_sections/performance.js b/src/nginxconfig/i18n/es/templates/global_sections/performance.js index 13eb80f..5103f9b 100644 --- a/src/nginxconfig/i18n/es/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/es/templates/global_sections/performance.js @@ -26,7 +26,9 @@ THE SOFTWARE. import common from '../../common'; -export default { +export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Compresión Gzip', enableGzipCompression: `${common.enable} compresión gzip`, brotliCompression: 'Compresión Brotli', @@ -38,5 +40,6 @@ export default { expirationForMedia: 'Expiración para media', expirationForSvgs: 'Expiración para SVGs', expirationForFonts: 'Expiración para fuentes', + performance: 'Rendimiento', }; diff --git a/src/nginxconfig/i18n/fr/templates/global_sections/performance.js b/src/nginxconfig/i18n/fr/templates/global_sections/performance.js index cffe6ae..4b866bd 100644 --- a/src/nginxconfig/i18n/fr/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/fr/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Compression Gzip', enableGzipCompression: `${common.enable} la compression gzip`, brotliCompression: 'Compression Brotli', diff --git a/src/nginxconfig/i18n/pl/templates/global_sections/performance.js b/src/nginxconfig/i18n/pl/templates/global_sections/performance.js index 5210161..6955669 100644 --- a/src/nginxconfig/i18n/pl/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/pl/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Kompresja gzip', enableGzipCompression: `${common.enable} kompresję gzip`, brotliCompression: 'Kompresja brotli', diff --git a/src/nginxconfig/i18n/pt-br/templates/global_sections/performance.js b/src/nginxconfig/i18n/pt-br/templates/global_sections/performance.js index 4edd124..61cc7a1 100644 --- a/src/nginxconfig/i18n/pt-br/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/pt-br/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Compressão Gzip', enableGzipCompression: `${common.enable} compressão gzip`, brotliCompression: 'Compressão Brotli', diff --git a/src/nginxconfig/i18n/ru/templates/global_sections/performance.js b/src/nginxconfig/i18n/ru/templates/global_sections/performance.js index 65e09cb..d721277 100644 --- a/src/nginxconfig/i18n/ru/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/ru/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Gzip сжатие', enableGzipCompression: `${common.enable} gzip сжатие`, brotliCompression: 'Brotli сжатие', diff --git a/src/nginxconfig/i18n/zh-cn/templates/global_sections/performance.js b/src/nginxconfig/i18n/zh-cn/templates/global_sections/performance.js index 4fcb828..d523bb9 100644 --- a/src/nginxconfig/i18n/zh-cn/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/zh-cn/templates/global_sections/performance.js @@ -34,6 +34,8 @@ export default { brotliIsANonStandardModule: 'Brotli 并不是一个 standard NGINX 模块, 请查看 ', brotliGoogleNgxBrotliProject: 'Google ngx_brotli 项目', brotliForBuildingNginxWithBrotli: ' 以构建支持 Brotli 的 NGINX!', + changesTakeEffect: '变更及时生效', + enableChangesTakeEffect: `${common.enable}变更及时生效`, expirationForAssets: '资源有效期', expirationForMedia: '媒体资源有效期', expirationForSvgs: 'SVGs有效期', diff --git a/src/nginxconfig/i18n/zh-tw/templates/global_sections/performance.js b/src/nginxconfig/i18n/zh-tw/templates/global_sections/performance.js index 812a739..daf3359 100644 --- a/src/nginxconfig/i18n/zh-tw/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/zh-tw/templates/global_sections/performance.js @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + changesTakeEffect: 'Changes take effect in time', + enableChangesTakeEffect: `${common.enable} changes take effect in time`, gzipCompression: 'Gzip 壓縮', enableGzipCompression: `${common.enable}Gzip壓縮`, brotliCompression: 'Brotli 壓縮', diff --git a/src/nginxconfig/templates/global_sections/performance.vue b/src/nginxconfig/templates/global_sections/performance.vue index 251377a..f462f77 100644 --- a/src/nginxconfig/templates/global_sections/performance.vue +++ b/src/nginxconfig/templates/global_sections/performance.vue @@ -26,6 +26,25 @@ THE SOFTWARE. @@ -154,6 +158,10 @@ THE SOFTWARE. import PrettyCheck from '../inputs/checkbox'; const defaults = { + changesTakeEffect: { + default: true, + enabled: true, + }, gzipCompression: { default: true, enabled: true, @@ -178,6 +186,7 @@ THE SOFTWARE. default: '7d', enabled: true, }, + }; export default { diff --git a/src/nginxconfig/util/angular_backwards_compatibility.js b/src/nginxconfig/util/angular_backwards_compatibility.js index 117d6fd..2e2da8c 100644 --- a/src/nginxconfig/util/angular_backwards_compatibility.js +++ b/src/nginxconfig/util/angular_backwards_compatibility.js @@ -45,6 +45,7 @@ const globalMap = { python_server: ['python', 'pythonServer'], + changesTakeEffect: ['performance', 'changesTakeEffect', oldBool], gzip: ['performance', 'gzipCompression', oldBool], brotli: ['performance', 'brotliCompression', oldBool], expires_assets: ['performance', 'assetsExpiration'], diff --git a/src/nginxconfig/util/types_extensions.js b/src/nginxconfig/util/types_extensions.js index 7da45ca..1f3b569 100644 --- a/src/nginxconfig/util/types_extensions.js +++ b/src/nginxconfig/util/types_extensions.js @@ -37,4 +37,5 @@ export const extensions = { 'docx?|dotx?|docm|dotm|' + 'xlsx?|xltx?|xlsm|xltm|' + 'pptx?|potx?|pptm|potm|ppsx?', + html: 'html', };