Skip to content

Commit

Permalink
Improve lighthouse score (#3918)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Aug 22, 2023
1 parent a63896f commit 1a0332c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 0 additions & 2 deletions packages/web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
<meta property="twitter:app:name:iphone" content="Audius Music">
<meta property="twitter:app:name:googleplay" content="Audius Music">

<link rel="preconnect" href="https://www.google-analytics.com" crossorigin>

<script
defer
onLoad="window.web3Loaded = true; window.dispatchEvent(new CustomEvent('WEB3_LOADED'))"
Expand Down
14 changes: 14 additions & 0 deletions packages/web/scripts/workers-site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'
/* globals GA, GA_ACCESS_TOKEN, SITEMAP, DISCOVERY_NODES, HTMLRewriter */

const DEBUG = false
const BROWSER_CACHE_TTL_SECONDS = 60 * 60 * 24

const discoveryNodes = DISCOVERY_NODES.split(',')
const discoveryNode =
Expand Down Expand Up @@ -287,6 +288,19 @@ async function handleEvent(event) {
.on('head', new SEOHandlerHead(pathname))
.on('body', new SEOHandlerBody())
.transform(asset)

// Adjust browser cache on assets that don't change frequently and/or
// are given unique hashes when they do.
if (
pathname.startsWith('/static') ||
pathname.startsWith('/scripts') ||
pathname.startsWith('/fonts')
) {
const response = new Response(rewritten.body, rewritten)
response.headers.set('cache-control', BROWSER_CACHE_TTL_SECONDS)
return response
}

return rewritten
} catch (e) {
return new Response(e.message || e.toString(), { status: 500 })
Expand Down

0 comments on commit 1a0332c

Please sign in to comment.