Skip to content

Commit 717e279

Browse files
committed
Enable registration of the service-worker
1 parent ab76576 commit 717e279

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

elements/cr-search-control/cr-search-control.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
}
4545
</style>
4646
<iron-ajax id="ajax"
47-
auto
4847
url="{{protocolSrc}}"
4948
handle-as="json"
5049
active-requests="{{requests}}"
@@ -133,7 +132,8 @@
133132
],
134133
properties: {
135134
protocolSrc: {
136-
value: String
135+
value: String,
136+
observer: 'fireAjax_'
137137
},
138138
inputActive: {
139139
type: Boolean,
@@ -210,6 +210,12 @@
210210
}
211211
},
212212

213+
fireAjax_: function() {
214+
if (this.protocolSrc) {
215+
this.$.ajax.generateRequest();
216+
}
217+
},
218+
213219
handleButtonActiveChange_: function() {
214220
this.inputActive = this.$.searchButton.active;
215221
},

gulpfile.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,24 @@ function build() {
132132
.then(() => {
133133
// Okay, now let's generate the Service Worker
134134
console.log('Generating the Service Worker...');
135+
const staticFileGlobs = [
136+
polymerJson.entrypoint,
137+
polymerJson.shell,
138+
].concat(polymerJson.extraDependencies)
139+
.concat(polymerJson.sources)
140+
// Statikk can not handle `.nojekyll` requests
141+
// Nonetheless, this file is only required to exist, so
142+
// we can just ignore it for caching.
143+
.filter(e => e !== '.nojekyll');
144+
135145
return polymerBuild.addServiceWorker({
136146
project: polymerProject,
137147
buildRoot: buildDirectory,
138148
bundled: true,
139-
swPrecacheConfig: swPrecacheConfig
149+
swPrecacheConfig: {
150+
staticFileGlobs,
151+
navigateFallback: polymerJson.entrypoint
152+
}
140153
});
141154
})
142155
.then(() => {

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ <h4 id="simultaneous">Does the protocol support multiple simultaneous clients?</
511511
toolbar.classList.remove('search-active');
512512
}, false);
513513
});
514+
515+
if ('serviceWorker' in window.navigator) {
516+
navigator.serviceWorker.register('service-worker.js');
517+
}
514518
})();
515519
</script>
516520
<script>

polymer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"_data/**/*",
1313
"_versions/**/*",
1414
"search_index/**/*",
15-
"bower_components/webcomponentsjs/*.js"
15+
"bower_components/webcomponentsjs/*.js",
16+
"bower_components/web-animations-js/web-animations-next.min.js"
1617
],
1718
"lint": {
1819
"rules": ["polymer-2"]

service-worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('ServiceWorker disabled in development mode.');

0 commit comments

Comments
 (0)