Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all usage of versioned_static to media methods #5694

Merged
merged 11 commits into from
Jan 7, 2020
12 changes: 6 additions & 6 deletions wagtail/admin/staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def versioned_static(path):
Wrapper for Django's static file finder to append a cache-busting query parameter
that updates on each Wagtail version
"""
base_url = static(path)

# if URL already contains a querystring, don't add our own, to avoid interfering
# with existing mechanisms
if VERSION_HASH is None or '?' in base_url:
return base_url
# if URL already contains a querystring or is an absolute path, then don't add the version
# querystring to avoid changing URLs which might interfere with existing mechanisms, or
# doesn't need cache-busting anyway
if VERSION_HASH is None or '?' in path or path.startswith(('http://', 'https://', '/')):
return path
tomkins marked this conversation as resolved.
Show resolved Hide resolved
else:
base_url = static(path)
return base_url + '?v=' + VERSION_HASH
12 changes: 12 additions & 0 deletions wagtail/admin/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ class TestVersionedStatic(TestCase):
def test_versioned_static(self):
result = versioned_static('wagtailadmin/js/core.js')
self.assertRegex(result, r'^/static/wagtailadmin/js/core.js\?v=(\w+)$')

def test_versioned_static_querystring(self):
result = versioned_static('wagtailadmin/js/core.js?version=1')
self.assertEqual(result, 'wagtailadmin/js/core.js?version=1')

def test_versioned_static_absolute_path(self):
result = versioned_static('/static/wagtailadmin/js/core.js')
self.assertEqual(result, '/static/wagtailadmin/js/core.js')

def test_versioned_static_url(self):
result = versioned_static('http://example.org/static/wagtailadmin/js/core.js')
self.assertEqual(result, 'http://example.org/static/wagtailadmin/js/core.js')