misc: serve minified jquery unless debug is on (#12372)
This commit is contained in:
parent
0dab32311b
commit
7e4ad2ff74
|
@ -161,3 +161,13 @@ def test_static_directories():
|
|||
|
||||
assert 'Directory listing denied' in get_app(pub).get('/static/css/').body
|
||||
assert get_app(pub).get('/static/xxx', status=404)
|
||||
|
||||
def test_jquery_debug_mode():
|
||||
FormDef.wipe()
|
||||
create_formdef()
|
||||
resp = get_app(pub).get('/category1/test-formdef-1/')
|
||||
assert 'jquery.min.js' in resp.body
|
||||
pub.cfg['debug'] = {'debug_mode': True}
|
||||
pub.write_cfg()
|
||||
resp = get_app(pub).get('/category1/test-formdef-1/')
|
||||
assert 'jquery.js' in resp.body
|
||||
|
|
|
@ -18,6 +18,7 @@ import time
|
|||
import traceback
|
||||
import sys
|
||||
|
||||
from quixote import get_publisher
|
||||
from quixote.util import randbytes
|
||||
import quixote.http_response
|
||||
from quixote import get_publisher, get_request
|
||||
|
@ -59,10 +60,14 @@ class HTTPResponse(quixote.http_response.HTTPResponse):
|
|||
def add_javascript(self, script_names):
|
||||
if not self.javascript_scripts:
|
||||
self.javascript_scripts = []
|
||||
debug_mode = get_publisher().cfg.get('debug', {}).get('debug_mode', False)
|
||||
mappings = {
|
||||
'jquery.js': '../xstatic/jquery.js',
|
||||
'jquery-ui.js': '../xstatic/jquery-ui.js',
|
||||
'jquery.js': '../xstatic/jquery.min.js',
|
||||
'jquery-ui.js': '../xstatic/jquery-ui.min.js',
|
||||
}
|
||||
if debug_mode:
|
||||
mappings['jquery.js'] = '../xstatic/jquery.js'
|
||||
mappings['jquery-ui.js'] = '../xstatic/jquery-ui.js'
|
||||
for script_name in script_names:
|
||||
mapped_script_name = mappings.get(script_name) or script_name
|
||||
if not mapped_script_name in self.javascript_scripts:
|
||||
|
|
Loading…
Reference in New Issue