From 041178a38a52cecbe7888583394bd6289cda165d Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 14 Nov 2024 20:47:26 -0800 Subject: [PATCH] Adding further cache optimizations, gzip compression, and minifying js --- crank/settings/base.py | 4 +--- crank/templatetags/socialapp_cache.py | 2 +- package-lock.json | 1 + package.json | 1 + webpack.config.js | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crank/settings/base.py b/crank/settings/base.py index 19907310..801a45ff 100644 --- a/crank/settings/base.py +++ b/crank/settings/base.py @@ -15,11 +15,8 @@ import os from pathlib import Path -from django.conf.global_settings import STATICFILES_DIRS, CACHE_MIDDLEWARE_SECONDS -from django.contrib.staticfiles.storage import ManifestStaticFilesStorage from dotenv import load_dotenv from opentelemetry.instrumentation.django import DjangoInstrumentor -from tests.test_settings import MANIFEST_LOADER load_dotenv() DjangoInstrumentor().instrument(is_sql_commentor_enabled=True) @@ -92,6 +89,7 @@ ) MIDDLEWARE = [ + 'django.middleware.gzip.GZipMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', diff --git a/crank/templatetags/socialapp_cache.py b/crank/templatetags/socialapp_cache.py index 0a0b2285..e9880f23 100644 --- a/crank/templatetags/socialapp_cache.py +++ b/crank/templatetags/socialapp_cache.py @@ -12,6 +12,6 @@ def get_cached_social_app(provider): cache_key = f'social_app_{provider}' social_app = cache.get(cache_key) if not social_app: - social_app = SocialApp.objects.filter(provider=provider).first() + social_app = SocialApp.objects.filter(provider=provider).prefetch_related('sites').first() cache.set(cache_key, social_app, timeout=settings.CACHE_MIDDLEWARE_SECONDS) return social_app \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index be998c16..ef8e47b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "jest-environment-jsdom": "^29.7.0", "jest-fetch-mock": "^3.0.3", "nodemon": "^3.1.7", + "terser-webpack-plugin": "^5.3.10", "ts-jest": "^29.2.5", "ts-loader": "^9.5.1", "ts-node": "^10.9.2", diff --git a/package.json b/package.json index 619b2737..3e5f2653 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "jest-environment-jsdom": "^29.7.0", "jest-fetch-mock": "^3.0.3", "nodemon": "^3.1.7", + "terser-webpack-plugin": "^5.3.10", "ts-jest": "^29.2.5", "ts-loader": "^9.5.1", "ts-node": "^10.9.2", diff --git a/webpack.config.js b/webpack.config.js index 1ce1a8dc..19b0acd3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,7 @@ const path = require('path'); const {CleanWebpackPlugin} = require('clean-webpack-plugin'); const {WebpackManifestPlugin} = require('webpack-manifest-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); const options = {}; @@ -24,7 +25,8 @@ module.exports = { }, mode: 'production', optimization: { - minimize: false + minimize: true, + minimizer: [new TerserPlugin()], }, plugins: [ new CleanWebpackPlugin(options),