@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.72 → 3.2.0-ultramodern.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,20 @@ function withCorsHeaders(response) {
|
|
|
19
19
|
statusText: response.statusText
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
function isFingerprintedAssetPathname(pathname) {
|
|
23
|
+
return /(?:^|\/)[^/]+\.[a-f0-9]{8,}\.(?:css|js|mjs|json|svg|png|jpe?g|webp|avif|gif|woff2?|ttf)$/iu.test(pathname);
|
|
24
|
+
}
|
|
25
|
+
function withAssetHeaders(response, request) {
|
|
26
|
+
const corsResponse = withCorsHeaders(response);
|
|
27
|
+
const headers = new Headers(corsResponse.headers);
|
|
28
|
+
const { pathname } = new URL(request.url);
|
|
29
|
+
if (isFingerprintedAssetPathname(pathname)) headers.set('cache-control', 'public, max-age=31536000, immutable');
|
|
30
|
+
return new Response(corsResponse.body, {
|
|
31
|
+
headers,
|
|
32
|
+
status: corsResponse.status,
|
|
33
|
+
statusText: corsResponse.statusText
|
|
34
|
+
});
|
|
35
|
+
}
|
|
22
36
|
function createCorsPreflightResponse(request) {
|
|
23
37
|
if ('OPTIONS' !== request.method) return null;
|
|
24
38
|
return new Response(null, {
|
|
@@ -31,7 +45,7 @@ async function fetchAsset(request, env) {
|
|
|
31
45
|
if (!assets || 'function' != typeof assets.fetch) return null;
|
|
32
46
|
const response = await assets.fetch(request);
|
|
33
47
|
if (404 === response.status) return null;
|
|
34
|
-
return
|
|
48
|
+
return withAssetHeaders(response, request);
|
|
35
49
|
}
|
|
36
50
|
async function fetchAssetByPath(pathname, request, env) {
|
|
37
51
|
const url = new URL(request.url);
|
|
@@ -259,12 +273,19 @@ async function withRouteCssLinks(response, route, routeManifest, request, env) {
|
|
|
259
273
|
...await collectRenderedRemoteCssHrefs(html, request, env)
|
|
260
274
|
];
|
|
261
275
|
if (0 === cssHrefs.length) return response;
|
|
262
|
-
const
|
|
276
|
+
const uniqueCssHrefs = [
|
|
263
277
|
...new Set(cssHrefs)
|
|
264
|
-
]
|
|
265
|
-
|
|
278
|
+
];
|
|
279
|
+
const headers = new Headers(response.headers);
|
|
280
|
+
for (const href of uniqueCssHrefs)headers.append('link', `<${href}>; rel=preload; as=style`);
|
|
281
|
+
const links = uniqueCssHrefs.filter((href)=>!html.includes(href)).map((href)=>`<link rel="stylesheet" href="${escapeAttribute(href)}">`);
|
|
282
|
+
if (0 === links.length || !html.includes('</head>')) return new Response(html, {
|
|
283
|
+
headers,
|
|
284
|
+
status: response.status,
|
|
285
|
+
statusText: response.statusText
|
|
286
|
+
});
|
|
266
287
|
return new Response(html.replace('</head>', `${links.join('')}</head>`), {
|
|
267
|
-
headers
|
|
288
|
+
headers,
|
|
268
289
|
status: response.status,
|
|
269
290
|
statusText: response.statusText
|
|
270
291
|
});
|
|
@@ -19,6 +19,20 @@ function withCorsHeaders(response) {
|
|
|
19
19
|
statusText: response.statusText
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
function isFingerprintedAssetPathname(pathname) {
|
|
23
|
+
return /(?:^|\/)[^/]+\.[a-f0-9]{8,}\.(?:css|js|mjs|json|svg|png|jpe?g|webp|avif|gif|woff2?|ttf)$/iu.test(pathname);
|
|
24
|
+
}
|
|
25
|
+
function withAssetHeaders(response, request) {
|
|
26
|
+
const corsResponse = withCorsHeaders(response);
|
|
27
|
+
const headers = new Headers(corsResponse.headers);
|
|
28
|
+
const { pathname } = new URL(request.url);
|
|
29
|
+
if (isFingerprintedAssetPathname(pathname)) headers.set('cache-control', 'public, max-age=31536000, immutable');
|
|
30
|
+
return new Response(corsResponse.body, {
|
|
31
|
+
headers,
|
|
32
|
+
status: corsResponse.status,
|
|
33
|
+
statusText: corsResponse.statusText
|
|
34
|
+
});
|
|
35
|
+
}
|
|
22
36
|
function createCorsPreflightResponse(request) {
|
|
23
37
|
if ('OPTIONS' !== request.method) return null;
|
|
24
38
|
return new Response(null, {
|
|
@@ -31,7 +45,7 @@ async function fetchAsset(request, env) {
|
|
|
31
45
|
if (!assets || 'function' != typeof assets.fetch) return null;
|
|
32
46
|
const response = await assets.fetch(request);
|
|
33
47
|
if (404 === response.status) return null;
|
|
34
|
-
return
|
|
48
|
+
return withAssetHeaders(response, request);
|
|
35
49
|
}
|
|
36
50
|
async function fetchAssetByPath(pathname, request, env) {
|
|
37
51
|
const url = new URL(request.url);
|
|
@@ -259,12 +273,19 @@ async function withRouteCssLinks(response, route, routeManifest, request, env) {
|
|
|
259
273
|
...await collectRenderedRemoteCssHrefs(html, request, env)
|
|
260
274
|
];
|
|
261
275
|
if (0 === cssHrefs.length) return response;
|
|
262
|
-
const
|
|
276
|
+
const uniqueCssHrefs = [
|
|
263
277
|
...new Set(cssHrefs)
|
|
264
|
-
]
|
|
265
|
-
|
|
278
|
+
];
|
|
279
|
+
const headers = new Headers(response.headers);
|
|
280
|
+
for (const href of uniqueCssHrefs)headers.append('link', `<${href}>; rel=preload; as=style`);
|
|
281
|
+
const links = uniqueCssHrefs.filter((href)=>!html.includes(href)).map((href)=>`<link rel="stylesheet" href="${escapeAttribute(href)}">`);
|
|
282
|
+
if (0 === links.length || !html.includes('</head>')) return new Response(html, {
|
|
283
|
+
headers,
|
|
284
|
+
status: response.status,
|
|
285
|
+
statusText: response.statusText
|
|
286
|
+
});
|
|
266
287
|
return new Response(html.replace('</head>', `${links.join('')}</head>`), {
|
|
267
|
-
headers
|
|
288
|
+
headers,
|
|
268
289
|
status: response.status,
|
|
269
290
|
statusText: response.statusText
|
|
270
291
|
});
|
|
@@ -19,6 +19,20 @@ function withCorsHeaders(response) {
|
|
|
19
19
|
statusText: response.statusText
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
function isFingerprintedAssetPathname(pathname) {
|
|
23
|
+
return /(?:^|\/)[^/]+\.[a-f0-9]{8,}\.(?:css|js|mjs|json|svg|png|jpe?g|webp|avif|gif|woff2?|ttf)$/iu.test(pathname);
|
|
24
|
+
}
|
|
25
|
+
function withAssetHeaders(response, request) {
|
|
26
|
+
const corsResponse = withCorsHeaders(response);
|
|
27
|
+
const headers = new Headers(corsResponse.headers);
|
|
28
|
+
const { pathname } = new URL(request.url);
|
|
29
|
+
if (isFingerprintedAssetPathname(pathname)) headers.set('cache-control', 'public, max-age=31536000, immutable');
|
|
30
|
+
return new Response(corsResponse.body, {
|
|
31
|
+
headers,
|
|
32
|
+
status: corsResponse.status,
|
|
33
|
+
statusText: corsResponse.statusText
|
|
34
|
+
});
|
|
35
|
+
}
|
|
22
36
|
function createCorsPreflightResponse(request) {
|
|
23
37
|
if ('OPTIONS' !== request.method) return null;
|
|
24
38
|
return new Response(null, {
|
|
@@ -31,7 +45,7 @@ async function fetchAsset(request, env) {
|
|
|
31
45
|
if (!assets || 'function' != typeof assets.fetch) return null;
|
|
32
46
|
const response = await assets.fetch(request);
|
|
33
47
|
if (404 === response.status) return null;
|
|
34
|
-
return
|
|
48
|
+
return withAssetHeaders(response, request);
|
|
35
49
|
}
|
|
36
50
|
async function fetchAssetByPath(pathname, request, env) {
|
|
37
51
|
const url = new URL(request.url);
|
|
@@ -259,12 +273,19 @@ async function withRouteCssLinks(response, route, routeManifest, request, env) {
|
|
|
259
273
|
...await collectRenderedRemoteCssHrefs(html, request, env)
|
|
260
274
|
];
|
|
261
275
|
if (0 === cssHrefs.length) return response;
|
|
262
|
-
const
|
|
276
|
+
const uniqueCssHrefs = [
|
|
263
277
|
...new Set(cssHrefs)
|
|
264
|
-
]
|
|
265
|
-
|
|
278
|
+
];
|
|
279
|
+
const headers = new Headers(response.headers);
|
|
280
|
+
for (const href of uniqueCssHrefs)headers.append('link', `<${href}>; rel=preload; as=style`);
|
|
281
|
+
const links = uniqueCssHrefs.filter((href)=>!html.includes(href)).map((href)=>`<link rel="stylesheet" href="${escapeAttribute(href)}">`);
|
|
282
|
+
if (0 === links.length || !html.includes('</head>')) return new Response(html, {
|
|
283
|
+
headers,
|
|
284
|
+
status: response.status,
|
|
285
|
+
statusText: response.statusText
|
|
286
|
+
});
|
|
266
287
|
return new Response(html.replace('</head>', `${links.join('')}</head>`), {
|
|
267
|
-
headers
|
|
288
|
+
headers,
|
|
268
289
|
status: response.status,
|
|
269
290
|
statusText: response.statusText
|
|
270
291
|
});
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.2.0-ultramodern.
|
|
20
|
+
"version": "3.2.0-ultramodern.73",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -99,16 +99,16 @@
|
|
|
99
99
|
"ndepe": "^0.1.13",
|
|
100
100
|
"pkg-types": "^2.3.1",
|
|
101
101
|
"std-env": "4.1.0",
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@modern-js/plugin
|
|
104
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.
|
|
105
|
-
"@modern-js/
|
|
106
|
-
"@modern-js/server
|
|
107
|
-
"@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.
|
|
108
|
-
"@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.
|
|
109
|
-
"@modern-js/
|
|
110
|
-
"@modern-js/
|
|
111
|
-
"@modern-js/
|
|
102
|
+
"@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.2.0-ultramodern.73",
|
|
103
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.73",
|
|
104
|
+
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.73",
|
|
105
|
+
"@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.73",
|
|
106
|
+
"@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.2.0-ultramodern.73",
|
|
107
|
+
"@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.73",
|
|
108
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.73",
|
|
109
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.73",
|
|
110
|
+
"@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.73",
|
|
111
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.73"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|
|
114
114
|
"@rslib/core": "0.21.5",
|