Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use mtime for build ID in dev for debugging.

Using time.time() for a build ID in dev breaks Firefox's script debugger
(see in particular bug 783393). This replaces time.time() with a helper
that returns time.time() for remote scripts and the file's mtime for
local scripts.
  • Loading branch information...
commit d2ffefbd31e5035873083107e86893be302ce452 1 parent bec565e
James Socol authored
Showing with 22 additions and 8 deletions.
  1. +10 −4 jingo_minify/helpers.py
  2. +12 −4 jingo_minify/tests.py
View
14 jingo_minify/helpers.py
@@ -68,11 +68,18 @@ def _get_item_path(item):
"""
Determine whether to return a relative path or a URL.
"""
- if item.startswith(('//', 'http', 'https')):
+ if item.startswith(('//', 'http://', 'https://')):
return item
return get_media_url() + item
+def _get_mtime(item):
+ """Get a last-changed timestamp for development."""
+ if item.startswith(('//', 'http://', 'https://')):
+ return int(time.time())
+ return int(os.path.getmtime(get_path(item)))
+
+
def _build_html(items, wrapping):
"""
Wrap `items` in wrapping.
@@ -91,7 +98,7 @@ def js(bundle, debug=settings.TEMPLATE_DEBUG, defer=False, async=False):
if debug:
# Add timestamp to avoid caching.
- items = ['%s?build=%s' % (item, int(time.time())) for item in
+ items = ['%s?build=%s' % (item, _get_mtime(item)) for item in
settings.MINIFY_BUNDLES['js'][bundle]]
else:
build_id = BUILD_ID_JS
@@ -132,7 +139,7 @@ def css(bundle, media=False, debug=settings.TEMPLATE_DEBUG):
items.append(item)
# Add timestamp to avoid caching.
- items = ['%s?build=%s' % (item, int(time.time())) for item in items]
+ items = ['%s?build=%s' % (item, _get_mtime(item)) for item in items]
else:
build_id = BUILD_ID_CSS
bundle_full = "css:%s" % bundle
@@ -175,4 +182,3 @@ def build_ids(request):
"""A context processor for injecting the css/js build ids."""
return {'BUILD_ID_CSS': BUILD_ID_CSS, 'BUILD_ID_JS': BUILD_ID_JS,
'BUILD_ID_IMG': BUILD_ID_IMG}
-
View
16 jingo_minify/tests.py
@@ -19,13 +19,15 @@ def setup():
@patch('jingo_minify.helpers.time.time')
-def test_js_helper(time):
+@patch('jingo_minify.helpers.os.path.getmtime')
+def test_js_helper(getmtime, time):
"""
Given the js() tag if we return the assets that make up that bundle
as defined in settings.MINIFY_BUNDLES.
If we're not in debug mode, we just return a minified url
"""
+ getmtime.return_value = 1
time.return_value = 1
env = jingo.env
@@ -84,13 +86,15 @@ def test_js_helper(time):
@patch('jingo_minify.helpers.time.time')
-def test_css_helper(time):
+@patch('jingo_minify.helpers.os.path.getmtime')
+def test_css_helper(getmtime, time):
"""
Given the css() tag if we return the assets that make up that bundle
as defined in settings.MINIFY_BUNDLES.
If we're not in debug mode, we just return a minified url
"""
+ getmtime.return_value = 1
time.return_value = 1
env = jingo.env
@@ -186,7 +190,9 @@ def test_static_override():
STATIC_URL='http://example.com/static/',
MEDIA_URL='http://example.com/media/')
@patch('jingo_minify.helpers.time.time')
-def test_css(time):
+@patch('jingo_minify.helpers.os.path.getmtime')
+def test_css(getmtime, time):
+ getmtime.return_value = 1
time.return_value = 1
env = jingo.env
@@ -206,7 +212,9 @@ def test_css(time):
STATIC_URL='http://example.com/static/',
MEDIA_URL='http://example.com/media/')
@patch('jingo_minify.helpers.time.time')
-def test_js(time):
+@patch('jingo_minify.helpers.os.path.getmtime')
+def test_js(getmtime, time):
+ getmtime.return_value = 1
time.return_value = 1
env = jingo.env
Please sign in to comment.
Something went wrong with that request. Please try again.