History

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

Jasper van Merle committed 7 years ago

Commit fef95891 parent 5e23f645 files · +9 −38Browse files

Unified · Split

5 files
  1. assets/javascripts/lib/page.coffee +2 −0
  2. assets/javascripts/templates/pages/settings_tmpl.coffee +1 −1
  3. assets/stylesheets/application.css.scss +2 −1
  4. assets/stylesheets/components/_environment.scss.erb +3 −0
  5. views/service-worker.js.erb +1 −36
assets/javascripts/lib/page.coffee+2−0
@@ -199,6 +199,8 @@ page.track = (fn) -> · 198 unmodified lines
199 return199 return
200 200
201track = ->201track = ->
202 return unless app.config.env == 'production'
203
202 consentGiven = Cookies.get('analyticsConsent')204 consentGiven = Cookies.get('analyticsConsent')
203 consentAsked = Cookies.get('analyticsConsentAsked')205 consentAsked = Cookies.get('analyticsConsentAsked')
204 206
assets/javascripts/templates/pages/settings_tmpl.coffee+1−1
@@ -19,7 +19,7 @@ app.templates.settingsPage = (settings) -> """ · 18 unmodified lines
19 <input type="checkbox" form="settings" name="autoInstall" value="_auto-install"#{if settings.autoInstall then ' checked' else ''}>Automatically download documentation for offline use19 <input type="checkbox" form="settings" name="autoInstall" value="_auto-install"#{if settings.autoInstall then ' checked' else ''}>Automatically download documentation for offline use
20 <small>Only enable this when bandwidth isn't a concern to you.</small>20 <small>Only enable this when bandwidth isn't a concern to you.</small>
21 </label>21 </label>
22 <label class="_settings-label">22 <label class="_settings-label _hide-in-development">
23 <input type="checkbox" form="settings" name="analyticsConsent"#{if settings.analyticsConsent then ' checked' else ''}>Enable tracking cookies23 <input type="checkbox" form="settings" name="analyticsConsent"#{if settings.analyticsConsent then ' checked' else ''}>Enable tracking cookies
24 <small>With this checked, we enable Google Analytics and Gauges to collect anonymous traffic information.</small>24 <small>With this checked, we enable Google Analytics and Gauges to collect anonymous traffic information.</small>
25 </label>25 </label>
assets/stylesheets/application.css.scss+2−1
@@ -29,7 +29,8 @@ · 28 unmodified lines
29 'components/path',29 'components/path',
30 'components/notice',30 'components/notice',
31 'components/prism',31 'components/prism',
32 'components/mobile';32 'components/mobile',
33 'components/environment';
33 34
34@import 'pages/simple',35@import 'pages/simple',
35 'pages/angular',36 'pages/angular',
assets/stylesheets/components/_environment.scss.erb+3−0
@@ -0,0 +1,3 @@
1._hide-in-development {
2 <%= App.environment != :production ? 'display: none;' : '' %>
3}
views/service-worker.js.erb+1−36
@@ -11,34 +11,6 @@ const urlsToCache = [ · 10 unmodified lines
11 '<%= doc_index_urls.join "',\n '" %>',11 '<%= doc_index_urls.join "',\n '" %>',
12];12];
13 13
14<%# Clone a request with the mode set to 'cors' %>
15function 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
42<%# Set-up the cache %>14<%# Set-up the cache %>
43self.addEventListener('install', event => {15self.addEventListener('install', event => {
44 self.skipWaiting();16 self.skipWaiting();
@@ -64,14 +36,7 @@ self.addEventListener('fetch', event => { · 19 unmodified lines
64 if (cachedResponse) return cachedResponse;36 if (cachedResponse) return cachedResponse;
65 37
66 try {38 try {
67 const response = await fetch(corsify(event.request));39 const response = await fetch(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
75 return response;40 return response;
76 } catch (err) {41 } catch (err) {
77 const url = new URL(event.request.url);42 const url = new URL(event.request.url);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t