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
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
@@ -19,7 +19,7 @@ app.templates.settingsPage = (settings) -> """ · 18 unmodified lines
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
@@ -29,7 +29,8 @@ · 28 unmodified lines
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',
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
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 => { · 19 unmodified lines
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);

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