Murder Chicken
Murder Chicken
CDCloudflare Developers
Created by will smith on 10/25/2024 in #pages-help
Avoiding waterfalls
4 replies
CDCloudflare Developers
Created by will smith on 10/25/2024 in #pages-help
Avoiding waterfalls
4 replies
CDCloudflare Developers
Created by will smith on 10/25/2024 in #pages-help
Avoiding waterfalls
Couple things to look into: * 304 status, ETAG/If-None-Match headers for client side caching. * Leverage CF cache API for server side caching
4 replies
CDCloudflare Developers
Created by Murder Chicken on 10/29/2024 in #workers-help
Static Assets HTML 304 local but 200 only when deployed
--- BONUS QUESTION As a follow up question, I'm seeing really strange behavior with local Workers using static assets. Take, for example, this very simple fetch handler...
export default {
async fetch(request, env, ctx) {
// console.log('TEST LOG');
const url = new URL(request.url);
let path = url.pathname;
try {
const response = await env.ASSETS.fetch(path);
if (response.status === 404) {
return new Response('Not Found', { status: 404 });
}
return response;
} catch (error) {
return new Response('Internal Error', { status: 500 });
}
},
};
export default {
async fetch(request, env, ctx) {
// console.log('TEST LOG');
const url = new URL(request.url);
let path = url.pathname;
try {
const response = await env.ASSETS.fetch(path);
if (response.status === 404) {
return new Response('Not Found', { status: 404 });
}
return response;
} catch (error) {
return new Response('Internal Error', { status: 500 });
}
},
};
So, ASSETS maps to the /public directory which has two HTML files. These will render properly. If I uncomment that console.log, it will not show up when I serve up the site locally. Furthermore, if I literally delete the entire contents of the fetch handler... reload the worker... I can still hit the site. What kind of caching is going on here that allows that?
10 replies
CDCloudflare Developers
Created by Murder Chicken on 10/29/2024 in #workers-help
Static Assets HTML 304 local but 200 only when deployed
Ok, I think I'm getting confused. So, if we have a worker leveraging static assets to deliver pre-compiled HTML (generated during the build process and pushed to the /public directory) to the browser, what's the best practice to ensure that it's taking advantage of proper best-practices for browser / server caching? What's confusing me is that when using npx wrangler dev to view the site locally, I'm seeing what I would expect... which is that on the initial load, a 200 response with an ETAG header and then upon second load, a 304 response with both ETAG and If-None-Match headers. However, when I deploy this simple script (which is deployed to a testing subdomain of my primary domain, i.e., sandbox.domain.com), I only see 200 responses for the HTML page." At first, I thought that this might have something to do with setting a Cache rule to enforce strong ETAGs. So, I created a cache rule for all incoming requests to respect strong ETAGs. Now the ETAGs show up and I see 304 responses but without bronti (or any) compression. So, I'm starting to get a bit lost about best practices here and any explanations would be appreciated.
10 replies