Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions vtex/loaders/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ const buildProxyRoutes = (
const urlToProxy = `https://${hostname}`;
const hostToUse = hostname;

// Versioned VTEX static assets (e.g. /files/foo.css?v=HASH) are immutable
// by definition: the hash changes whenever the content does. VTEX upstream
// serves them with short TTLs, so we force `immutable` on the proxy hop
// when the request carries a `v` query param. Unversioned variants of the
// same path keep upstream Cache-Control.
const IMMUTABLE_ASSET_PATHS = new Set([
"/files/*",
"/assets/*",
"/arquivos/*",
]);

const routeFromPath = (pathTemplate: string): Route => {
const handlerValue = {
__resolveType: "website/handlers/proxy.ts",
Expand All @@ -88,12 +77,6 @@ const buildProxyRoutes = (
includeScriptsToBody,
removeDirtyCookies: true,
pathsThatRequireSameReferer: VTEX_PATHS_THAT_REQUIRES_SAME_REFERER,
...(IMMUTABLE_ASSET_PATHS.has(pathTemplate) && {
cacheControl: {
value: "public, max-age=31536000, immutable",
matchQueryParam: "v",
},
}),
};

return ({
Expand Down
28 changes: 0 additions & 28 deletions website/handlers/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,6 @@ export interface Props {
removeDirtyCookies?: boolean;
excludeHeaders?: string[];
pathsThatRequireSameReferer?: string[];
/**
* @description Override Cache-Control on proxied responses. Use when the
* upstream (e.g. VTEX IO) sends a Cache-Control that does not
* match the resource's true cacheability — for example
* versioned static assets at /files/*?v=HASH which are
* immutable but get short upstream TTLs.
*
* When matchQueryParam is set, the override only applies if
* that query param is present on the incoming request URL.
* This lets you safely opt in only the versioned variant of a
* path (e.g. matchQueryParam: "v" → /files/x.js?v=abc gets
* overridden, /files/x.js does not).
*
* Only applied when the upstream response is 2xx, so error
* responses retain their upstream caching semantics.
*/
cacheControl?: {
value: string;
matchQueryParam?: string;
};
}
/**
* @title Proxy
Expand All @@ -124,7 +104,6 @@ export default function Proxy({
replaces,
removeDirtyCookies = false,
pathsThatRequireSameReferer = [],
cacheControl,
}: Props): Handler {
return async (req, _ctx) => {
const url = new URL(req.url);
Expand Down Expand Up @@ -239,13 +218,6 @@ export default function Proxy({
responseHeaders.set("location", location.replace(proxyUrl, url.origin));
}
}
if (cacheControl && response.ok) {
const matches = !cacheControl.matchQueryParam ||
url.searchParams.has(cacheControl.matchQueryParam);
if (matches) {
responseHeaders.set("Cache-Control", cacheControl.value);
}
}
let text: undefined | string = undefined;
if (replaces && replaces.length > 0 && contentType?.includes("text/html")) {
if (response.ok) {
Expand Down
Loading