Simplify service worker and don't show analytics setting/notification in development

pull/1066/head
Jasper van Merle 6 years ago
parent 5e23f645b1
commit fef9589fae

@ -199,6 +199,8 @@ page.track = (fn) ->
return
track = ->
return unless app.config.env == 'production'
consentGiven = Cookies.get('analyticsConsent')
consentAsked = Cookies.get('analyticsConsentAsked')

@ -19,7 +19,7 @@ app.templates.settingsPage = (settings) -> """
<input type="checkbox" form="settings" name="autoInstall" value="_auto-install"#{if settings.autoInstall then ' checked' else ''}>Automatically download documentation for offline use
<small>Only enable this when bandwidth isn't a concern to you.</small>
</label>
<label class="_settings-label">
<label class="_settings-label _hide-in-development">
<input type="checkbox" form="settings" name="analyticsConsent"#{if settings.analyticsConsent then ' checked' else ''}>Enable tracking cookies
<small>With this checked, we enable Google Analytics and Gauges to collect anonymous traffic information.</small>
</label>

@ -29,7 +29,8 @@
'components/path',
'components/notice',
'components/prism',
'components/mobile';
'components/mobile',
'components/environment';
@import 'pages/simple',
'pages/angular',

@ -0,0 +1,3 @@
._hide-in-development {
<%= App.environment != :production ? 'display: none;' : '' %>
}

@ -11,34 +11,6 @@ const urlsToCache = [
'<%= doc_index_urls.join "',\n '" %>',
];
<%# Clone a request with the mode set to 'cors' %>
function corsify(request) {
const options = {
mode: 'cors',
};
const keys = [
'body',
'cache',
'credentials',
'headers',
'integrity',
'keepalive',
'method',
'redirect',
'referrer',
'referrerPolicy',
'signal',
'window',
];
for (const key of keys) {
options[key] = request[key];
}
return new Request(request.url, options);
}
<%# Set-up the cache %>
self.addEventListener('install', event => {
self.skipWaiting();
@ -64,14 +36,7 @@ self.addEventListener('fetch', event => {
if (cachedResponse) return cachedResponse;
try {
const response = await fetch(corsify(event.request));
<%# If the status code is 0 it means the response is opaque %>
<%# If the response is opaque it's not possible to read whether it is successful or not, so we assume it is %>
if (!response.ok && response.status !== 0) {
throw new Error(`The HTTP request failed with status code ${response.status}`);
}
const response = await fetch(event.request);
return response;
} catch (err) {
const url = new URL(event.request.url);

Loading…
Cancel
Save