Let's do ES modules for browsers that support them

This commit is contained in:
Timothy Warren 2018-09-14 11:56:48 -04:00
parent 09530efefd
commit 2fc26bf4c6
7 changed files with 16 additions and 14 deletions

View File

@ -11,9 +11,11 @@
</div> </div>
</section> </section>
<?php if ($auth->isAuthenticated()): ?> <?php if ($auth->isAuthenticated()): ?>
<script async="async" defer="defer" src="<?= $urlGenerator->assetUrl('js/scripts-authed.min.js') ?>"></script> <script nomodule async="async" defer="defer" src="<?= $urlGenerator->assetUrl('js/scripts-authed.min.js') ?>"></script>
<script type="module" src="<?= $urlGenerator->assetUrl('js/src/index-authed.js') ?>"></script>
<?php else: ?> <?php else: ?>
<script async="async" defer="defer" src="<?= $urlGenerator->assetUrl('js/scripts.min.js') ?>"></script> <script nomodule async="async" defer="defer" src="<?= $urlGenerator->assetUrl('js/scripts.min.js') ?>"></script>
<script type="module" src="<?= $urlGenerator->assetUrl('js/src/index.js') ?>"></script>
<?php endif ?> <?php endif ?>
</body> </body>
</html> </html>

View File

@ -1,5 +1,5 @@
import _ from './base/AnimeClient' import _ from './base/AnimeClient.js'
import { renderAnimeSearchResults } from './template-helpers' import { renderAnimeSearchResults } from './template-helpers.js'
const search = (query) => { const search = (query) => {
// Show the loader // Show the loader

View File

@ -1,4 +1,4 @@
import _ from './AnimeClient'; import _ from './AnimeClient.js';
/** /**
* Event handlers * Event handlers
*/ */

View File

@ -1,4 +1,4 @@
import './index'; import './index.js';
import './anime'; import './anime.js';
import './manga'; import './manga.js';

View File

@ -1,4 +1,4 @@
import './base/events'; import './base/events.js';
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(reg => { navigator.serviceWorker.register('/sw.js').then(reg => {

View File

@ -1,5 +1,5 @@
import _ from './base/AnimeClient' import _ from './base/AnimeClient.js'
import { renderMangaSearchResults } from './template-helpers' import { renderMangaSearchResults } from './template-helpers.js'
const search = (query) => { const search = (query) => {
_.$('.cssload-loader')[ 0 ].removeAttribute('hidden'); _.$('.cssload-loader')[ 0 ].removeAttribute('hidden');

6
sw.js
View File

@ -21,7 +21,7 @@ async function update (request) {
return response; return response;
} }
function refresh (response) { /* function refresh (response) {
return self.clients.matchAll().then(clients => { return self.clients.matchAll().then(clients => {
clients.forEach(client => { clients.forEach(client => {
const message = { const message = {
@ -33,7 +33,7 @@ function refresh (response) {
client.postMessage(JSON.stringify(message)); client.postMessage(JSON.stringify(message));
}) })
}); });
} } */
self.addEventListener('install', event => { self.addEventListener('install', event => {
console.log('Public Folder Worker installed'); console.log('Public Folder Worker installed');
@ -70,6 +70,6 @@ self.addEventListener('fetch', event => {
}); });
event.waitUntil( event.waitUntil(
update(event.request).then(refresh) update(event.request)
); );
}); });