OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 6 Code distributed by Google as part of the polymer project is also |
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 8 --> |
| 9 <link rel="import" href="../polymer/polymer.html"> |
| 10 |
| 11 <script> |
| 12 /** |
| 13 * The `<platinum-sw-import-script>` element is used to import a JavaScript fi
le that is executed |
| 14 * each time the service worker starts up. |
| 15 * |
| 16 * `<platinum-sw-import-script>` needs to be a child element of `<platinum-sw-
register>`. |
| 17 * |
| 18 * A common use case is to define a custom request handler for a `fetch` event
, but it can be used |
| 19 * for any type of code that you want to be executed by the service worker. |
| 20 * |
| 21 * <platinum-sw-register> |
| 22 * <platinum-sw-import-script href="custom-fetch-handler.js"></platinum-
sw-import-script> |
| 23 * <platinum-sw-fetch handler="customFetchHandler" |
| 24 * path="/(.*)/customFetch"></platinum-sw-fetch> |
| 25 * </platinum-sw-register> |
| 26 * |
| 27 * You can specify multiple `<platinum-sw-import-script>` elements, each one c
orresponding to a |
| 28 * different JavaScript file. The JavaScript files will be loaded in the order
in which the |
| 29 * `<platinum-sw-import-script>` elements appear. Under the hood, this results
in an |
| 30 * [`importScripts()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker
GlobalScope/importScripts) |
| 31 * call made from the context of the service worker. |
| 32 */ |
| 33 Polymer({ |
| 34 is: 'platinum-sw-import-script', |
| 35 |
| 36 properties: { |
| 37 /** |
| 38 * The URL of the JavaScript file that you want imported. |
| 39 * |
| 40 * Relative URLs are assumed to be |
| 41 * relative to the service worker's script location, which will almost alw
ays be the same |
| 42 * location as the page which includes this element. |
| 43 */ |
| 44 href: String |
| 45 }, |
| 46 |
| 47 _getParameters: function() { |
| 48 return new Promise(function(resolve) { |
| 49 var params = {}; |
| 50 if (this.href) { |
| 51 params.importscript = this.href; |
| 52 } |
| 53 resolve(params); |
| 54 }.bind(this)); |
| 55 } |
| 56 }); |
| 57 </script> |
OLD | NEW |