Skip to content

Commit

Permalink
refactor(asset-proxy): increase cache of cf edge and set it for browser
Browse files Browse the repository at this point in the history
  • Loading branch information
hugotiburtino committed Oct 31, 2024
1 parent 69abfbe commit c2030ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/asset-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ test('request to https://asset-proxy.serlo.org/image?url=* gets asset from url q
expect(response.status).toBe(200)
expect(response.headers.get('content-type')).toBe('image/png')
expect(response.headers.get('Set-Cookie')).toBeNull()
expect(response.headers.get('cache-control')).toBe(
'public, max-age=31536000, immutable',
)
})

describe('returns placeholder', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/asset-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export async function assetProxy(request: Request): Promise<Response | null> {
}

const originalResponse = await fetch(assetUrl, {
cf: { cacheTtl: 24 * 60 * 60 },
cf: { cacheTtl: 24 * 60 * 60 * 30 },
})

if (originalResponse.ok && isImageResponse(originalResponse)) {
const response = new Response(originalResponse.body, originalResponse)
response.headers.delete('set-cookie')
response.headers.set('cache-control', 'public, max-age=31536000, immutable')
return response
}

Expand Down

0 comments on commit c2030ce

Please sign in to comment.