Skip to content

Commit fef9589

Browse files
committed
Simplify service worker and don't show analytics setting/notification in development
1 parent 5e23f64 commit fef9589

File tree

5 files changed

+9
-38
lines changed

5 files changed

+9
-38
lines changed

assets/javascripts/lib/page.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ page.track = (fn) ->
199199
return
200200

201201
track = ->
202+
return unless app.config.env == 'production'
203+
202204
consentGiven = Cookies.get('analyticsConsent')
203205
consentAsked = Cookies.get('analyticsConsentAsked')
204206

assets/javascripts/templates/pages/settings_tmpl.coffee

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

assets/stylesheets/application.css.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
'components/path',
3030
'components/notice',
3131
'components/prism',
32-
'components/mobile';
32+
'components/mobile',
33+
'components/environment';
3334

3435
@import 'pages/simple',
3536
'pages/angular',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
._hide-in-development {
2+
<%= App.environment != :production ? 'display: none;' : '' %>
3+
}

views/service-worker.js.erb

+1-36
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,6 @@ const urlsToCache = [
1111
'<%= doc_index_urls.join "',\n '" %>',
1212
];
1313

14-
<%# Clone a request with the mode set to 'cors' %>
15-
function corsify(request) {
16-
const options = {
17-
mode: 'cors',
18-
};
19-
20-
const keys = [
21-
'body',
22-
'cache',
23-
'credentials',
24-
'headers',
25-
'integrity',
26-
'keepalive',
27-
'method',
28-
'redirect',
29-
'referrer',
30-
'referrerPolicy',
31-
'signal',
32-
'window',
33-
];
34-
35-
for (const key of keys) {
36-
options[key] = request[key];
37-
}
38-
39-
return new Request(request.url, options);
40-
}
41-
4214
<%# Set-up the cache %>
4315
self.addEventListener('install', event => {
4416
self.skipWaiting();
@@ -64,14 +36,7 @@ self.addEventListener('fetch', event => {
6436
if (cachedResponse) return cachedResponse;
6537

6638
try {
67-
const response = await fetch(corsify(event.request));
68-
69-
<%# If the status code is 0 it means the response is opaque %>
70-
<%# If the response is opaque it's not possible to read whether it is successful or not, so we assume it is %>
71-
if (!response.ok && response.status !== 0) {
72-
throw new Error(`The HTTP request failed with status code ${response.status}`);
73-
}
74-
39+
const response = await fetch(event.request);
7540
return response;
7641
} catch (err) {
7742
const url = new URL(event.request.url);

0 commit comments

Comments
 (0)