diff options
| author | Pierre Paridans <app@odoo.com> | 2020-09-24 12:55:54 +0000 |
|---|---|---|
| committer | Pierre Paridans <app@odoo.com> | 2020-10-02 12:21:48 +0000 |
| commit | 052bc7665e89426fb51928e43bd4a15dbf6cb705 (patch) | |
| tree | 880f646f10e2341564daec38b0c2d2835f4713f9 /addons/website_event_track/controllers | |
| parent | 47fdfb8ae73ab79100fb83751ff0f132b4a5c628 (diff) | |
[FIX] website_event_track: only cache local & cdn based urls
This commit allows to filter out the requests to local-ish domains (cf.
the current host and an optionally configured CDN for the current
website) and preventing from cluttering the cache used by the
ServiceWorker with tracking files, scripts or other non-necessary
assets.
This allows to even further reduce the possible "opaque" requests from
being stored in the cache (as they use way more space than regular/basic
responses).
Diffstat (limited to 'addons/website_event_track/controllers')
| -rw-r--r-- | addons/website_event_track/controllers/webmanifest.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/addons/website_event_track/controllers/webmanifest.py b/addons/website_event_track/controllers/webmanifest.py index 9f4967ed70d..627c2581577 100644 --- a/addons/website_event_track/controllers/webmanifest.py +++ b/addons/website_event_track/controllers/webmanifest.py @@ -48,8 +48,13 @@ class TrackManifest(http.Controller): """ Returns a ServiceWorker javascript file scoped for website_event """ sw_file = get_module_resource('website_event_track', 'static/src/js/service_worker.js') - with open(sw_file, 'rb') as fp: + with open(sw_file, 'r') as fp: body = fp.read() + js_cdn_url = 'undefined' + if request.website.cdn_activated: + cdn_url = request.website.cdn_url.replace('"','%22').replace('\x5c','%5C') + js_cdn_url = '"%s"' % cdn_url + body = body.replace('__ODOO_CDN_URL__', js_cdn_url) response = request.make_response(body, [ ('Content-Type', 'text/javascript'), ('Service-Worker-Allowed', url_for('/event')), |
