fix cross origin issue for assets
This commit is contained in:
parent
49b7483cdb
commit
aa4c34dd01
|
|
@ -74,7 +74,7 @@ class FootComposer
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$scripts[] = [
|
$scripts[] = [
|
||||||
'src' => 'https://cdn.jsdelivr.net/npm/@blessing-skin/admin-lte@3.0/dist/admin-lte.min.js',
|
'src' => 'https://cdn.jsdelivr.net/npm/@blessing-skin/admin-lte@3.0.4/dist/admin-lte.min.js',
|
||||||
'integrity' => 'sha256-lEpMZPtZ0RgHYZFOcJeX94WMegvHJ+beF5V7XtCcWxY=',
|
'integrity' => 'sha256-lEpMZPtZ0RgHYZFOcJeX94WMegvHJ+beF5V7XtCcWxY=',
|
||||||
'crossorigin' => 'anonymous',
|
'crossorigin' => 'anonymous',
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,11 @@ class Hook
|
||||||
});
|
});
|
||||||
if ($matched) {
|
if ($matched) {
|
||||||
$urls->each(function ($url) use (&$links) {
|
$urls->each(function ($url) use (&$links) {
|
||||||
$links[] = ['rel' => 'stylesheet', 'href' => $url];
|
$links[] = [
|
||||||
|
'rel' => 'stylesheet',
|
||||||
|
'href' => $url,
|
||||||
|
'crossorigin' => 'anonymous',
|
||||||
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +93,7 @@ class Hook
|
||||||
});
|
});
|
||||||
if ($matched) {
|
if ($matched) {
|
||||||
$urls->each(function ($url) use (&$scripts) {
|
$urls->each(function ($url) use (&$scripts) {
|
||||||
$scripts[] = ['src' => $url];
|
$scripts[] = ['src' => $url, 'crossorigin' => 'anonymous'];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,14 @@ import {
|
||||||
} from 'workbox-strategies'
|
} from 'workbox-strategies'
|
||||||
import { ExpirationPlugin } from 'workbox-expiration'
|
import { ExpirationPlugin } from 'workbox-expiration'
|
||||||
|
|
||||||
|
const oneWeek = 7 * 24 * 3600
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
registerRoute(/\.js/, new NetworkOnly())
|
registerRoute(/\.js/, new NetworkOnly())
|
||||||
registerRoute(/\.css/, new NetworkOnly())
|
registerRoute(/\.css/, new NetworkOnly())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#region Pictures
|
||||||
registerRoute(
|
registerRoute(
|
||||||
/\/preview\/\d+/,
|
/\/preview\/\d+/,
|
||||||
new CacheFirst({
|
new CacheFirst({
|
||||||
|
|
@ -18,7 +21,9 @@ registerRoute(
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
},
|
},
|
||||||
plugins: [new ExpirationPlugin({ maxAgeSeconds: 7 * 24 * 60 * 60 })],
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -39,45 +44,96 @@ registerRoute(
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
},
|
},
|
||||||
|
plugins: [new ExpirationPlugin({ maxAgeSeconds: oneWeek })],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
registerRoute(/.+\/\d+\.js$/, new NetworkOnly())
|
//#endregion
|
||||||
|
|
||||||
|
//#region jsDelivr
|
||||||
registerRoute(
|
registerRoute(
|
||||||
/\/app\/\w{2,3}\.\w{7}\.js$/,
|
/.*cdn\.jsdelivr\.net/,
|
||||||
|
new CacheFirst({
|
||||||
|
cacheName: 'jsdelivr-v1',
|
||||||
|
fetchOptions: {
|
||||||
|
credentials: 'omit',
|
||||||
|
mode: 'cors',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region JavaScript files
|
||||||
|
registerRoute(
|
||||||
|
/.+\/app\/\w{2,3}\.\w{7}\.js$/,
|
||||||
new CacheFirst({
|
new CacheFirst({
|
||||||
cacheName: 'javascript-v1',
|
cacheName: 'javascript-v1',
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
|
mode: 'cors',
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
registerRoute(
|
registerRoute(
|
||||||
({ request }) => request.destination === 'script',
|
/.+\/plugins\/.+\.js$/,
|
||||||
new StaleWhileRevalidate({
|
new StaleWhileRevalidate({
|
||||||
cacheName: 'javascript-v1',
|
cacheName: 'javascript-v1',
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
|
mode: 'cors',
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region CSS files
|
||||||
|
registerRoute(
|
||||||
|
/.+\/app\/.*\.css$/,
|
||||||
|
new CacheFirst({
|
||||||
|
cacheName: 'stylesheet-v1',
|
||||||
|
fetchOptions: {
|
||||||
|
credentials: 'omit',
|
||||||
|
mode: 'cors',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
registerRoute(
|
registerRoute(
|
||||||
({ request }) => request.destination === 'style',
|
/.+\/plugins\/.+\.css$/,
|
||||||
new StaleWhileRevalidate({
|
new StaleWhileRevalidate({
|
||||||
cacheName: 'stylesheet-v1',
|
cacheName: 'stylesheet-v1',
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
|
mode: 'cors',
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region Fonts
|
||||||
registerRoute(
|
registerRoute(
|
||||||
({ request }) => request.destination === 'font',
|
({ request }) => request.destination === 'font',
|
||||||
new StaleWhileRevalidate({
|
new StaleWhileRevalidate({
|
||||||
cacheName: 'font-v1',
|
cacheName: 'font-v1',
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
|
mode: 'cors',
|
||||||
},
|
},
|
||||||
|
plugins: [new ExpirationPlugin({ maxEntries: 12 })],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
//#endregion
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if home_page_css_loader %}
|
{% if home_page_css_loader %}
|
||||||
<script src="{{ home_page_css_loader }}"></script>
|
<script src="{{ home_page_css_loader }}" crossorigin="anonymous"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script type="application/json" id="blessing-extra">
|
<script type="application/json" id="blessing-extra">
|
||||||
{{ {transparent_navbar: transparent_navbar}|json_encode|raw }}
|
{{ {transparent_navbar: transparent_navbar}|json_encode|raw }}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user