Skip to content

Commit 68f4023

Browse files
yeion7SaraVieira
authored andcommitted
Improve performance home page (codesandbox#2677)
* Ensure text remains visible during webfont load * not blocking render with search doc * use lazy load native
1 parent 6e5f289 commit 68f4023

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports.onClientEntry = () => {
2+
(function addDocSearch() {
3+
const path = `https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css`;
4+
const link = document.createElement(`link`);
5+
link.setAttribute(`rel`, `stylesheet`);
6+
link.setAttribute(`type`, `text/css`);
7+
link.setAttribute(`href`, path);
8+
document.head.appendChild(link);
9+
})();
10+
};

packages/homepage/gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = {
6868
`source sans pro:300,400,500,600,700`,
6969
'open sans:300,400',
7070
],
71+
display: 'swap',
7172
},
7273
},
7374
{

packages/homepage/src/components/Companies.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export default ({ companies }) => (
2626
rel="noopener noreferrer"
2727
aria-label={`${company.name} is using CodeSandbox`}
2828
>
29-
<img height="150" src={company.logoURL} alt={company.name} />
29+
<img
30+
height="150"
31+
src={company.logoURL}
32+
alt={company.name}
33+
loading="lazy"
34+
/>
3035
</a>
3136
</div>
3237
))}

packages/homepage/src/html.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ export default function HTML(props) {
1414
name="viewport"
1515
content="width=device-width, initial-scale=1, shrink-to-fit=no"
1616
/>
17-
<link
18-
rel="stylesheet"
19-
href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"
20-
/>
2117
{props.headComponents}
2218
</head>
2319
<body {...props.bodyAttributes}>
@@ -32,7 +28,7 @@ export default function HTML(props) {
3228
/>
3329
{props.postBodyComponents}
3430
{JS_NPM_URLS.map(url => (
35-
<script key={url} src={url} />
31+
<script key={url} src={url} defer />
3632
))}
3733
</body>
3834
</html>

packages/homepage/src/screens/home/NPMFeature/EmbedAnimation/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default class EmbedAnimation extends React.PureComponent {
7575
alt="Browser"
7676
style={{ boxShadow: '0 5px 8px rgba(0, 0, 0, 0.3)' }}
7777
src={browserSvg}
78+
loading="lazy"
7879
/>
7980
<AbsoluteImage
8081
ref={el => {

packages/homepage/src/screens/home/NPMFeature/SearchInput/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const SearchInput = () => {
5757
style={{ marginTop: '1rem' }}
5858
width={160}
5959
src={algoliaImage}
60+
loading="lazy"
6061
/>
6162
</a>
6263
</div>

packages/homepage/src/screens/home/Patron/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export default () => (
6868

6969
<Content>
7070
<Badge>
71-
<img width={200} src={getBadge('patron_4')} alt="Patron IV" />
71+
<img
72+
width={200}
73+
src={getBadge('patron_4')}
74+
alt="Patron IV"
75+
loading="lazy"
76+
/>
7277
</Badge>
7378
<Button target="_blank" rel="noreferrer noopener" href="/patron">
7479
Open Patron Page

0 commit comments

Comments
 (0)