Skip to content

Commit

Permalink
chore: improve LCP performance (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
2color authored Jun 13, 2024
1 parent 7517a62 commit 0c6d601
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<meta name="robots" content="noindex" />
</head>
<body>
<div id="root" class="montserrat f5"></div>
<div id="root" class="sans-serif f5"></div>
</body>
</html>
2 changes: 1 addition & 1 deletion src/components/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'

export default function About (): JSX.Element {
return (
<aside className='mw7 lb-snow center w-100 lh-copy'>
<aside className='mw7 lb-snow center w-100 lh-copy pa2'>
<h1 className='pa0 f3 ma0 mb4 teal tc'>About the IPFS Gateway and Service Worker</h1>
<p>This page runs an IPFS gateway within a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API" target="_blank">Service Worker</a>. It uses <a href="https://github.com/ipfs/helia" target="_blank">Helia</a> (IPFS implementation in JS) and the <a href="https://github.com/ipfs/helia-verified-fetch" target="_blank">@helia/verified-fetch</a> library (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API" target="_blank">Fetch API</a> for IPFS) to facilitate direct verified retrieval of <a href="https://docs.ipfs.tech/concepts/content-addressing/" target="_blank">content-addressed</a> data.</p>
<p><strong>Why?</strong> It improves decentralization, offers enhanced security (CID verification happens on end user's machine) and reliability (ability to do retrieval from multiple sources without reliance on a single HTTP server).</p>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import ipfsLogo from '../ipfs-logo.svg'
export default function Header (): JSX.Element {
const { gotoPage } = React.useContext(RouteContext)
return (
<header className='e2e-header flex items-center pa3 bg-navy bb bw3 b--aqua tc justify-between'>
<header className='e2e-header flex items-center pa2 bg-navy bb bw3 b--aqua tc justify-between'>
<div>
<a href='https://ipfs.tech' title='IPFS Project' target="_blank" rel="noopener noreferrer" aria-label="Open IPFS Project's website">
<img alt='IPFS logo' src={ipfsLogo} style={{ height: 50 }} className='v-top' />
</a>
</div>
<div className='pb1 ma0 inline-flex items-center'>
<h1 className='e2e-header-title f3 fw2 montserrat aqua ttu'>Service Worker Gateway <small className="gray">(beta)</small></h1>
<h1 className='e2e-header-title f3 fw2 aqua ttu sans-serif'>Service Worker Gateway <small className="gray">(beta)</small></h1>
<button className='e2e-header-config-button pl3'
onClick={() => {
gotoPage('/ipfs-sw-config')
Expand Down
10 changes: 4 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import ReactDOMClient from 'react-dom/client'
import App from './app.jsx'
import { RouterProvider, type Route } from './context/router-context.jsx'
import * as renderChecks from './lib/routing-render-checks.js'

// SW did not trigger for this request
const container = document.getElementById('root')
Expand All @@ -15,13 +16,10 @@ const LazyInterstitial = React.lazy(async () => import('./pages/redirects-inters

const routes: Route[] = [
{ default: true, component: LazyHelperUi },
{ shouldRender: async () => (await import('./lib/routing-render-checks.js')).shouldRenderRedirectsInterstitial(), component: LazyInterstitial },
{ path: '#/ipfs-sw-config', shouldRender: async () => (await import('./lib/routing-render-checks.js')).shouldRenderConfigPage(), component: LazyConfig },
{ shouldRender: async () => renderChecks.shouldRenderRedirectsInterstitial(), component: LazyInterstitial },
{ path: '#/ipfs-sw-config', shouldRender: async () => renderChecks.shouldRenderConfigPage(), component: LazyConfig },
{
shouldRender: async () => {
const renderChecks = await import('./lib/routing-render-checks.js')
return renderChecks.shouldRenderRedirectPage()
},
shouldRender: async () => renderChecks.shouldRenderRedirectPage(),
component: LazyRedirectPage
}
]
Expand Down
3 changes: 3 additions & 0 deletions src/pages/default-page-styles.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
@import 'tachyons';
@import 'ipfs-css';

/* ensure we don't fetch any external fonts */
.sans-serif { font-family: system-ui, sans-serif; }
2 changes: 1 addition & 1 deletion src/pages/helper-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function HelperUi (): React.JSX.Element {
return (
<>
<Header />
<main className='pa4-l bg-snow mw7 mv5 center pa4'>
<main className='pa2 pa4-l bg-snow mw7 mv5-l center'>
<h1 className='pa0 f3 ma0 mb4 teal tc'>Fetch & Verify IPFS Content in Browser</h1>
<Form
handleSubmit={handleSubmit}
Expand Down
24 changes: 20 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const paths = {
*/
const prod = {
mode: 'production',
devtool: 'inline-source-map',
devtool: 'source-map',
performance: {
hints: false,
maxEntrypointSize: 512000,
Expand Down Expand Up @@ -266,13 +266,29 @@ const common = {
// Images: Copy image files to build folder
{ test: /\.(?:ico|gif|png|jpg|jpeg)$/i, type: 'asset/resource' },

// Fonts and SVGs: Inline files
{ test: /\.(woff2|svg|)$/, type: 'asset/inline' },
// Inline SVGs
{ test: /\.(svg|)$/, type: 'asset/inline' },
{
test: /\.(sa|sc|c)ss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
{
loader: 'css-loader',
options: {
url: {
// Exclude fonts from build
filter: (url, resourcePath) => {
const fontRegex = /\.(otf|woff|woff2)/

if (url.search(fontRegex)) {
return false
}

return true
}
}
}
}
]
}
]
Expand Down

0 comments on commit 0c6d601

Please sign in to comment.