From c42f708cb5db7ac16982e974a90e1a9c12f8eb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A6=E4=BA=AE=E4=BA=AE?= Date: Sun, 12 Feb 2017 14:25:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0js/css=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DjangoBlog/settings.py | 26 ++++++++++++++++++- requirements.txt | 3 ++- templates/share_layout/base.html | 32 ++++++++++++++---------- templates/share_layout/base_account.html | 29 +++++++++++---------- 4 files changed, 62 insertions(+), 28 deletions(-) diff --git a/DjangoBlog/settings.py b/DjangoBlog/settings.py index c45127d..a7c5c93 100644 --- a/DjangoBlog/settings.py +++ b/DjangoBlog/settings.py @@ -43,7 +43,8 @@ INSTALLED_APPS = [ 'blog', 'accounts', 'comments', - 'oauth' + 'oauth', + 'compressor' ] MIDDLEWARE_CLASSES = [ @@ -272,3 +273,26 @@ LOGGING = { }, } } + + + +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + #other + 'compressor.finders.CompressorFinder', +) +COMPRESS_ENABLED = True +#COMPRESS_OFFLINE = True + +""" +COMPRESS_CSS_FILTERS = [ + #creates absolute urls from relative ones + 'compressor.filters.css_default.CssAbsoluteFilter', + #css minimizer + 'compressor.filters.cssmin.CSSMinFilter' +] +COMPRESS_JS_FILTERS = [ + 'compressor.filters.jsmin.JSMinFilter' +] +""" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 64266d6..c00bddd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,5 @@ Unidecode Whoosh mistune pygments -django-ipware \ No newline at end of file +django-ipware +django_compressor \ No newline at end of file diff --git a/templates/share_layout/base.html b/templates/share_layout/base.html index 7db1549..8cc2fd8 100644 --- a/templates/share_layout/base.html +++ b/templates/share_layout/base.html @@ -1,5 +1,6 @@ {% load static %} {% load cache %} +{% load compress %} - - - - - {% comment %}{% endcomment %} - - + + {% block compress_css %} + {% endblock %} + {% endcompress %} {% comment %} {% endcomment %} - - + {% compress js %} + + {% endcompress %} @@ -88,8 +90,12 @@ var wpAutoTopSpeed = 1; {% comment %} {% endcomment %} - - + {% compress js %} + + + {% block compress_js %} + {% endblock %} + {% endcompress %} {% block footer %} {% endblock %} diff --git a/templates/share_layout/base_account.html b/templates/share_layout/base_account.html index e1df7d6..d95a1ad 100644 --- a/templates/share_layout/base_account.html +++ b/templates/share_layout/base_account.html @@ -11,19 +11,22 @@ {{ SITE_NAME }} | {{ SITE_DESCRIPTION }} + {% load compress %} + {% compress css %} + + - - - - - - - - - - - - + + + + + + + {% endcompress %} + {% compress js %} + + + {% endcompress %} - + \ No newline at end of file