Hey folks,
Does anyone know how to define cache control for app proxy routes that return Liquid?
Base route:
export const loader = async ({ request }) => {
const { liquid } = await authenticate.public.appProxy(request);
return liquid(
`{
"shop": "{{ shop.name }}"
}`,
{
layout: false,
},
);
};
Attempt 1: Passing the headers option in the liquid function
export const loader = async ({ request }) => {
const { liquid } = await authenticate.public.appProxy(request);
return liquid(
`{
"shop": "{{ shop.name }}"
}`,
{
layout: false,
headers: {
'Cache-Control':
'public, max-age=31536000, s-maxage=31536000, immutable',
},
},
);
};
Attempt 2: Modifying the response headers
export const loader = async ({ request }) => {
const { liquid } = await authenticate.public.appProxy(request);
const response = await liquid(
`{
"shop": "{{ shop.name }}"
}`,
{
layout: false,
},
);
const headers = new Headers(response.headers);
headers.set(
'Cache-Control',
'public, max-age=31536000, s-maxage=31536000, immutable',
);
return new Response(response.body, {
headers,
});
};
Neither of these pass the cache control through. The code is for the clarity of the example. The end goal is to reduce the amounts of calls to our servers when we know that the data isn’t changing often. As we’re growing, we see up to 200 requests a minute for a route that really ought to be cached by the browser and Cloudflare.
Any help is appreciated!