This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathplatinum-sw-import-script.html
68 lines (65 loc) · 2.59 KB
/
platinum-sw-import-script.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<script>
/**
* The `<platinum-sw-import-script>` element is used to import a JavaScript file
* that is executed each time the service worker starts up.
*
* `<platinum-sw-import-script>` needs to be a child element of
* `<platinum-sw-register>`.
*
* A common use case is to define a custom request handler for a `fetch` event,
* but it can be used for any type of code that you want to be executed by the
* service worker.
*
* <platinum-sw-register auto-register>
* <platinum-sw-import-script
* href="custom-fetch-handler.js"></platinum-sw-import-script>
* <platinum-sw-fetch handler="customFetchHandler"
* path="/(.*)/customFetch"></platinum-sw-fetch>
* </platinum-sw-register>
*
* You can specify multiple `<platinum-sw-import-script>` elements, each one
* corresponding to a different JavaScript file. The JavaScript files will be
* loaded in the order in which the
* `<platinum-sw-import-script>` elements appear. Under the hood, this results
* in an
* [`importScripts()`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts)
* call made from the context of the service worker.
*/
Polymer({
is: 'platinum-sw-import-script',
properties: {
/**
* The URL of the JavaScript file that you want imported.
*
* Relative URLs are assumed to be
* relative to the service worker's script location, which will almost
* always be the same location as the page which includes this element.
*/
href: String
},
_getParameters: function() {
return new Promise(function(resolve) {
var params = {};
if (this.href) {
params.importscript = this.href;
} else {
Polymer.Base._warn(
'The following platinum-sw-import-script element will not have any effect.' +
' The "href" attribute must be set.',
this);
}
resolve(params);
}.bind(this));
}
});
</script>