diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 2d5ce8eada2..355ce5a9418 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -59,11 +59,7 @@ else: env = jinja2.Environment(loader=loader, autoescape=True) env.filters["json"] = json.dumps -# 1 week cache for asset bundles as advised by Google Page Speed -BUNDLE_MAXAGE = 60 * 60 * 24 * 7 - -# 1 year cache for content (menus, translations, static qweb) -CONTENT_MAXAGE = 60 * 60 * 24 * 356 +CONTENT_MAXAGE = http.STATIC_CACHE_LONG # menus, translations, static qweb DBNAME_PATTERN = '^[a-zA-Z0-9][a-zA-Z0-9_.-]+$' @@ -889,7 +885,7 @@ class WebClient(http.Controller): file_open('web/static/lib/moment/locale/%s.js' % code, 'rb') ), content_type='application/javascript; charset=utf-8', - headers=[('Cache-Control', 'max-age=36000')], + headers=[('Cache-Control', 'max-age=%s' % http.STATIC_CACHE)], direct_passthrough=True, ) except IOError: @@ -897,7 +893,7 @@ class WebClient(http.Controller): return request.make_response("", headers=[ ('Content-Type', 'application/javascript'), - ('Cache-Control', 'max-age=36000'), + ('Cache-Control', 'max-age=%s' % http.STATIC_CACHE), ]) @http.route('/web/webclient/qweb/', type='http', auth="none", cors="*") diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index 64ab86aea9b..cc76a8d0ff9 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -20,7 +20,7 @@ import werkzeug.utils import odoo from odoo import api, http, models, tools, SUPERUSER_ID from odoo.exceptions import AccessDenied, AccessError -from odoo.http import request, STATIC_CACHE, content_disposition +from odoo.http import request, content_disposition from odoo.tools import consteq, pycompat from odoo.tools.mimetypes import guess_mimetype from odoo.modules.module import get_resource_path, get_module_path @@ -393,7 +393,7 @@ class IrHttp(models.AbstractModel): headers.append(('ETag', filehash)) if etag == filehash and status == 200: status = 304 - headers.append(('Cache-Control', 'max-age=%s' % (STATIC_CACHE if unique else 0))) + headers.append(('Cache-Control', 'max-age=%s' % (http.STATIC_CACHE_LONG if unique else 0))) # content-disposition default name if download: headers.append(('Content-Disposition', content_disposition(filename))) diff --git a/odoo/http.py b/odoo/http.py index 9e0da1768fc..a332baeadb2 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -58,8 +58,11 @@ _logger = logging.getLogger(__name__) rpc_request = logging.getLogger(__name__ + '.rpc.request') rpc_response = logging.getLogger(__name__ + '.rpc.response') -# 1 week cache for statics as advised by Google Page Speed -STATIC_CACHE = 60 * 60 * 24 * 7 +# One week cache for static content (static files in apps, library files, ...) +# Safe resources may use what google page speed recommends (1 year) +# (attachments with unique hash in the URL, ...) +STATIC_CACHE = 3600 * 24 * 7 +STATIC_CACHE_LONG = 3600 * 24 * 365 # To remove when corrected in Babel babel.core.LOCALE_ALIASES['nb'] = 'nb_NO'