diff options
| author | Fabien Meghazi <fme@openerp.com> | 2014-06-24 18:52:38 +0200 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2014-06-24 18:52:38 +0200 |
| commit | aa97aaa9d7ca7adc7ed46ee3f4805d30f5717b4e (patch) | |
| tree | de8f22d628e06460b9de71bea4909a163685c3c9 /addons/web | |
| parent | 0e9aca1013ff5c9fa9eb7ab90fad43f56b0d34a6 (diff) | |
[ADD] Assets Bundle versioning and better cache handling
An asset bundle is now versionned with the dates of the
ir.ui.views that compose it and also with the dates of
the files and ir.attachments linked inside the bundle.
This new behavior is reflected in the bundle's lru cache
managment.
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/controllers/main.py | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 98f65075922..09416179725 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -49,6 +49,9 @@ else: env = jinja2.Environment(loader=loader, autoescape=True) env.filters["json"] = simplejson.dumps +# 1 week cache for asset bundles as advised by Google Page Speed +BUNDLE_MAXAGE = 60 * 60 * 24 * 7 + #---------------------------------------------------------- # OpenERP Web helpers #---------------------------------------------------------- @@ -547,37 +550,31 @@ class Home(http.Controller): def login(self, db, login, key, redirect="/web", **kw): return login_and_redirect(db, login, key, redirect_url=redirect) - @http.route('/web/js/<xmlid>', type='http', auth="public") - def js_bundle(self, xmlid, **kw): - # manifest backward compatible mode, to be removed - values = {'manifest_list': manifest_list} + @http.route([ + '/web/js/<xmlid>', + '/web/js/<xmlid>/<sha>', + ], type='http', auth='public') + def js_bundle(self, xmlid, sha=None, **kw): try: - assets_html = request.render(xmlid, lazy=False, qcontext=values) + bundle = AssetsBundle(xmlid, debug=request.debug) except QWebTemplateNotFound: return request.not_found() - bundle = AssetsBundle(xmlid, assets_html, debug=request.debug) - response = request.make_response( - bundle.js(), [('Content-Type', 'application/javascript')]) - - # TODO: check that we don't do weird lazy overriding of __call__ which break body-removal - return make_conditional( - response, bundle.last_modified, bundle.checksum, max_age=60*60*24) + response = request.make_response(bundle.js(), [('Content-Type', 'application/javascript')]) + return make_conditional(response, bundle.last_modified, max_age=BUNDLE_MAXAGE) - @http.route('/web/css/<xmlid>', type='http', auth='public') - def css_bundle(self, xmlid, **kw): - values = {'manifest_list': manifest_list} # manifest backward compatible mode, to be removed + @http.route([ + '/web/css/<xmlid>', + '/web/css/<xmlid>/<sha>', + ], type='http', auth='public') + def css_bundle(self, xmlid, sha=None, **kw): try: - assets_html = request.render(xmlid, lazy=False, qcontext=values) + bundle = AssetsBundle(xmlid, debug=request.debug) except QWebTemplateNotFound: return request.not_found() - bundle = AssetsBundle(xmlid, assets_html, debug=request.debug) - - response = request.make_response( - bundle.css(), [('Content-Type', 'text/css')]) - return make_conditional( - response, bundle.last_modified, bundle.checksum, max_age=60*60*24) + response = request.make_response(bundle.css(), [('Content-Type', 'text/css')]) + return make_conditional(response, bundle.last_modified, max_age=BUNDLE_MAXAGE) class WebClient(http.Controller): |
