mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 03:31:04 +01:00
Disable querystrings if a storage backend with hashed filenames is active
This commit is contained in:
parent
8711050e49
commit
779620e53b
@ -1,12 +1,34 @@
|
||||
import hashlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles.storage import HashedFilesMixin
|
||||
from django.core.files.storage import get_storage_class
|
||||
from django.templatetags.static import static
|
||||
|
||||
from wagtail import __version__
|
||||
|
||||
|
||||
if getattr(settings, 'WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS', True):
|
||||
# Check whether we should add cache-busting '?v=...' parameters to static file URLs
|
||||
try:
|
||||
# If a preference has been explicitly stated in the WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS
|
||||
# setting, use that
|
||||
use_version_strings = settings.WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS
|
||||
except AttributeError:
|
||||
# If WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS not specified, default to version strings
|
||||
# enabled, UNLESS we're using a storage backend with hashed filenames; in this case having
|
||||
# a query parameter is redundant, and in some configurations (e.g. Cloudflare with the
|
||||
# "No Query String" setting) it could break a previously-working cache setup
|
||||
|
||||
if settings.DEBUG:
|
||||
# Hashed filenames are disabled in debug mode, so keep the querystring
|
||||
use_version_strings = True
|
||||
else:
|
||||
# see if we're using a storage backend using hashed filenames
|
||||
storage = get_storage_class(settings.STATICFILES_STORAGE)
|
||||
use_version_strings = not issubclass(storage, HashedFilesMixin)
|
||||
|
||||
|
||||
if use_version_strings:
|
||||
VERSION_HASH = hashlib.sha1(
|
||||
(__version__ + settings.SECRET_KEY).encode('utf-8')
|
||||
).hexdigest()[:8]
|
||||
|
Loading…
Reference in New Issue
Block a user