From 479162576d291d2c930ba37cf322af56ff5dd307 Mon Sep 17 00:00:00 2001 From: ChenYuhao Date: Wed, 15 Jun 2022 06:05:09 +0800 Subject: [PATCH] Add option to disable caching for HTML content (#366) * feat: Global performance improve add no-cache for html * feat: Disable HTML caching * fix: eslint check * Clean up --- .../generators/conf/general.conf.js | 13 +++++++++++- .../templates/global_sections/performance.js | 4 +++- .../templates/global_sections/performance.js | 4 +++- .../templates/global_sections/performance.js | 6 ++++-- .../templates/global_sections/performance.js | 4 +++- .../templates/global_sections/performance.js | 4 +++- .../templates/global_sections/performance.js | 4 +++- .../templates/global_sections/performance.js | 4 +++- .../templates/global_sections/performance.js | 6 ++++-- .../templates/global_sections/performance.js | 2 ++ .../templates/global_sections/performance.vue | 21 +++++++++++++++++++ src/nginxconfig/util/types_extensions.js | 3 ++- 12 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/nginxconfig/generators/conf/general.conf.js b/src/nginxconfig/generators/conf/general.conf.js index 52b5d69..a1f32f2 100644 --- a/src/nginxconfig/generators/conf/general.conf.js +++ b/src/nginxconfig/generators/conf/general.conf.js @@ -1,5 +1,5 @@ /* -Copyright 2020 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -41,6 +41,17 @@ export default (domains, global) => { }; if (global.logging.accessLog.computed) config['location = /robots.txt'].access_log = 'off'; + if (global.performance.disableHtmlCaching.computed) { + // Disable HTML caching for changes take effect in time + config['# Disable HTML caching'] = ''; + 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) { diff --git a/src/nginxconfig/i18n/de/templates/global_sections/performance.js b/src/nginxconfig/i18n/de/templates/global_sections/performance.js index 808c8db..8561498 100644 --- a/src/nginxconfig/i18n/de/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/de/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate 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..0bd4eb9 100644 --- a/src/nginxconfig/i18n/en/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/en/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: 'Disable HTML caching', + enableDisableHtmlCaching: 'disable HTML caching', 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..3b42872 100644 --- a/src/nginxconfig/i18n/es/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/es/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -26,7 +26,9 @@ THE SOFTWARE. import common from '../../common'; -export default { +export default { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate gzipCompression: 'Compresión Gzip', enableGzipCompression: `${common.enable} compresión gzip`, brotliCompression: 'Compresión Brotli', diff --git a/src/nginxconfig/i18n/fr/templates/global_sections/performance.js b/src/nginxconfig/i18n/fr/templates/global_sections/performance.js index cffe6ae..40a75f9 100644 --- a/src/nginxconfig/i18n/fr/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/fr/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate 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..45429f8 100644 --- a/src/nginxconfig/i18n/pl/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/pl/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate 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..abbb9ad 100644 --- a/src/nginxconfig/i18n/pt-br/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/pt-br/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate 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..95f8c7e 100644 --- a/src/nginxconfig/i18n/ru/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/ru/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,6 +27,8 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate 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..5b493ae 100644 --- a/src/nginxconfig/i18n/zh-cn/templates/global_sections/performance.js +++ b/src/nginxconfig/i18n/zh-cn/templates/global_sections/performance.js @@ -1,5 +1,5 @@ /* -Copyright 2021 DigitalOcean +Copyright 2022 DigitalOcean This code is licensed under the MIT License. You may obtain a copy of the License at @@ -27,8 +27,10 @@ THE SOFTWARE. import common from '../../common'; export default { + disableHtmlCaching: '禁用 HTML 缓存', + enableDisableHtmlCaching: '禁用 HTML 缓存', gzipCompression: 'Gzip 压缩', - enableGzipCompression: `${common.enable}Gzip压缩`, + enableGzipCompression: `${common.enable} Gzip 压缩`, brotliCompression: 'Brotli 压缩', enableBrotliCompression: `${common.enable} Brotli 压缩`, brotliIsANonStandardModule: 'Brotli 并不是一个 standard NGINX 模块, 请查看 ', 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 024d204..0db7ae7 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 { + disableHtmlCaching: 'Disable HTML caching', // TODO: translate + enableDisableHtmlCaching: 'disable HTML caching', // TODO: translate 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..04ed37b 100644 --- a/src/nginxconfig/templates/global_sections/performance.vue +++ b/src/nginxconfig/templates/global_sections/performance.vue @@ -26,6 +26,23 @@ THE SOFTWARE.