Skip to content

Commit

Permalink
Prefetch on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 9, 2024
1 parent c987cfa commit 3252deb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
"webpackMode": "eager",
"fetch": "eager",
"enabled": true
},
"prefetch-on-demand": {
"main": "src/prefetch-on-demand_controller.js",
"name": "pwa/prefetch-on-demand",
"webpackMode": "eager",
"fetch": "eager",
"enabled": true
}
},
"importmap": {
Expand Down
24 changes: 24 additions & 0 deletions assets/src/prefetch-on-demand_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

import { Controller } from '@hotwired/stimulus';

/* stimulusFetch: 'lazy' */
export default class extends Controller {
static values = {
urls: { type: Array, default: []}
};

connect = () => {
const workbox = window.workbox;
if (!workbox) {
return;
}

workbox.messageSW({
"type": "PREFETCH",
"payload": {
"urls": this.urlsValue
}
});
}
}

0 comments on commit 3252deb

Please sign in to comment.