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>
</section>
<?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: ?>
<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 ?>
</body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

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

6
sw.js
View File

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