Serhii Bilonoh
Serhii Bilonoh
CDCloudflare Developers
Created by Serhii Bilonoh on 9/12/2024 in #workers-help
Old assets availability with `--old-asset-ttl`
I'm trying to make outdated assets from the previous deployment available using --old-asset-ttl option (Thanks for @Peter Belbin https://github.com/cloudflare/workers-sdk/pull/3384). Unfortunately, assets aren't available using the old link from the browser after deployment. They are still in KV as expected but are not present in __STATIC_CONTENT_MANIFEST anymore. So can't be reached from browser by initial name (without hash prefix). I'm using a custom build with webpack to build my React app (not Wrangler internal bundler) and npx wrangler deploy -c wrangler.toml -e "<MY_ENV>" --old-asset-ttl=43200 to deploy. And finally, my fetch func in Worker is very simple
export default {
async fetch(request, env, ctx) {
const additionalHeaders = await getAdditionalHeaders(request, env)
const page = await getAssetFromKV(
{
request,
waitUntil: ctx.waitUntil.bind(ctx),
},
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: assetManifest,
mapRequestToAsset: serveSinglePageApp,
},
)

return addHeaders(request, new Response(page.body, page), env, additionalHeaders)
},
}
export default {
async fetch(request, env, ctx) {
const additionalHeaders = await getAdditionalHeaders(request, env)
const page = await getAssetFromKV(
{
request,
waitUntil: ctx.waitUntil.bind(ctx),
},
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: assetManifest,
mapRequestToAsset: serveSinglePageApp,
},
)

return addHeaders(request, new Response(page.body, page), env, additionalHeaders)
},
}
What I'm missing in using --old-asset-ttl? How to make it work?
3 replies