Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove service worker #936

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 0 additions & 82 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path');
const gulp = require('gulp');
const babel = require("gulp-babel");
const del = require('del');
const swPrecache = require('sw-precache');
const uglifyEs = require('gulp-uglify-es');
const uglify = uglifyEs.default;
const gulpLoadPlugins = require('gulp-load-plugins');
Expand Down Expand Up @@ -119,86 +118,6 @@ gulp.task('clean', () => {
], {dot: true});
});

// Generate a service worker file that will provide offline functionality for
// local resources.
gulp.task('generate-service-worker', () => {
const staticDir = 'static';
const distDir = path.join(staticDir, 'dist');
const filepath = path.join(distDir, 'service-worker.js');

return swPrecache.write(filepath, {
cacheId: 'chromestatus',
verbose: true,
logger: $.util.log,
staticFileGlobs: [
// Images
`${staticDir}/img/{browsers-logos.png,*.svg,crstatus_128.png,github-white.png}`,
// Scripts
`${staticDir}/js/**/!(*.es6).js`, // Don't include unminimized/untranspiled js.
],
runtimeCaching: [{ // Server-side generated content
// The features page, which optionally has a trailing slash or a
// feature id. For example:
// - /features
// - /features/
// - /features/<numeric feature id>
// This overly-specific regex is required to avoid matching other
// static content (i.e. /static/css/features/features.css)
urlPattern: /\/features(\/(\w+)?)?$/,
handler: 'fastest',
options: {
cache: {
maxEntries: 10,
name: 'features-cache'
}
}
}, {
// The metrics pages (optionally with a trailing slash)
// - /metrics/css/animated
// - /metrics/css/timeline/animated
// - /metrics/css/popularity
// - /metrics/css/timeline/popularity
// - /metrics/feature/popularity
// - /metrics/feature/timeline/popularity
urlPattern: /\/metrics\/(css|feature)\/(timeline\/)?(animated|popularity)(\/)?$/,
handler: 'fastest',
options: {
cache: {
maxEntries: 10,
name: 'metrics-cache'
}
}
}, {
// The samples page (optionally with a trailing slash)
urlPattern: /\/samples(\/)?$/,
handler: 'fastest',
options: {
cache: {
maxEntries: 10,
name: 'samples-cache'
}
}
}, {
// For dynamic data (json), use "fastest" so liefi scenarios are fast.
// "fastest" also makes a network request to update the cached copy.
// The worst case is that the user with an active SW gets stale content
// and never refreshes the page.
// TODO: use sw-toolbox notifyOnCacheUpdate when it's ready
// https://github.com/GoogleChrome/sw-toolbox/pull/174/
urlPattern: /\/data\//,
handler: 'fastest'
}, {
urlPattern: /\/features(_v\d+)?.json$/,
handler: 'fastest'
}, {
urlPattern: /\/samples.json$/,
handler: 'fastest'
}, {
urlPattern: /\/omaha_data$/,
handler: 'fastest'
}]
});
});

// Build production files, the default task
gulp.task('default', gulp.series(
Expand All @@ -207,7 +126,6 @@ gulp.task('default', gulp.series(
'js',
'lint-fix',
'rollup',
'generate-service-worker',
));

// Build production files, the default task
Expand Down
47 changes: 0 additions & 47 deletions static/js-src/features-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,58 +86,11 @@ window.addEventListener('popstate', (e) => {
featureListEl.addEventListener('app-ready', () => {
document.body.classList.remove('loading');

// Want "Caching is complete" toast to be slightly delayed after page load.
// To do that, wait to register SW until features have loaded.
registerServiceWorker();

// Lazy load Firebase messaging SDK after features list visible.
loadFirebaseSDKLibs().then(() => {
PushNotifications.init(); // init Firebase messaging.

// If use already granted the notification permission, update state of the
// push icon for each feature the user is subscribed to.
if (PushNotifier.GRANTED_ACCESS) {
PushNotifications.getAllSubscribedFeatures().then((subscribedFeatures) => {
const iconEl = document.querySelector('#features-subscribe-button').firstElementChild;
if (subscribedFeatures.includes(PushNotifier.ALL_FEATURES_TOPIC_ID)) {
iconEl.icon = 'chromestatus:notifications';
} else {
iconEl.icon = 'chromestatus:notifications-off';
}
});
}
});

StarService.getStars().then((starredFeatureIds) => {
featureListEl.starredFeatures = new Set(starredFeatureIds);
});
});

if (PushNotifier.SUPPORTS_NOTIFICATIONS) {
const subscribeButtonEl = document.querySelector('#features-subscribe-button');
subscribeButtonEl.removeAttribute('hidden');

subscribeButtonEl.addEventListener('click', (e) => {
e.preventDefault();

if (window.Notification && Notification.permission === 'denied') {
alert('Notifications were previously denied. Please reset the browser permission.');
return;
}

PushNotifications.getAllSubscribedFeatures().then(subscribedFeatures => {
const iconEl = document.querySelector('#features-subscribe-button').firstElementChild;
if (subscribedFeatures.includes(PushNotifier.ALL_FEATURES_TOPIC_ID)) {
iconEl.icon = 'chromestatus:notifications-off';
PushNotifications.unsubscribeFromFeature();
} else {
iconEl.icon = 'chromestatus:notifications';
PushNotifications.subscribeToFeature();
}
});
});
}

legendEl.views = VIEWS;

document.querySelector('.legend-button').addEventListener('click', (e) => {
Expand Down
Loading