
Let's get a little distracted from the coronavirus, and talk about something technical. For example, about how we tried to improve the cold start time of one react application and what came of it. Who cares about the topic of performance and fast web as a whole - please, under cat. At the end there will be a small survey about the price / need for such optimizations.
First, a little context. Usually we make different banking applications, which are mostly not accessible to the general public. But recently a small miracle happened and we were given the task of writing a public application (let's say, almost public). Of the basic requirements, only mobile-first, react, and IE can not be supported (even 11). Of the features - a one-time app (i.e., the user does not go there more often than once a year) and without data the application is absolutely and completely useless. It is useless to such an extent that we cannot even show a footer, because we donβt know in what color to show it and what to write there at all.
, . . Angular, , react, " ", " " . , , , " " Vue. , legacy .
. β react-router-dom, β mobx. β SCSS ( ) + css.modules . . , . "-" PureComponent React.memo, bundlesize + source-map-explorer. , .
, *. - mobile-first, client-facing, . . β . . . , , - UI . , , , + . Server Side Rendering. , , , .NET, . β .
* , ?
0,
- , , . , ( β 1000ms) Performance Audit devtools (online 4x CPU slowdown). :
- Firts Paint (FP): 618ms
- First Meaningful Paint (FMP): 2090ms
FP , (), FMP , UI ( ) - . , , 1000 ms (+) . , , . . β 4g* fast 3g **.
, 4g β 2270ms . , , , .
* 4g preset- - . β : download 4000kb/s, upload 3000kb/s, latency 20ms:
** *** , .
*** -, 3 , 10. , β , .
1, React.lazy
, . :
Index.html, React, . js β . , . , , . , .
, *, . β React.lazy, , . , lazy , , . .
:
( ). , , , . ? shared , App.tsx. . , .
* , .
2, Core LazyComponent
, shared module . shared core , , β , , - .
, , , React.Lazy. "" , . , . , . : , . :
export const LazyComponent = <T extends {}>(importStatement: () => Promise<{ default: ComponentType<T> }>) => {
const component = React.lazy(importStatement);
return { component, load: importStatement };
};
:
, , , 400ms fast3g - . . .
3, Spinner
, , . , ? "" ! , index.html , . index.html "" ? , . css, .
? , FP . FMP? :
. , .
, fast3g. , , , , - .
4,
. β¦ ! , . / index.html . . . Fetch IE ( ), promise . . .
index.html :
(function(){const path = `${window.app.api}`; window.app.data = fetch(path); }());
. , promis- , , . β . , index.html .
:
. 300ms . , . , . , .
, API , . preconnect, API. Preconnect IE 11
.
5,
, ? , , . . , ?
LazyComponent ( , ), suspense, . :
FP ( ). FMP . ? β - , , . , JS , index.html . :

.
, css. - , , CSS . JS ( ). ? β . , CSS JS . , css , JS ( , ), CSS , JS .
6,
. β .
, , , . β¦ , . ! , font-weight 100 .
, , :
- . . . - .
- ( 5-6 , HTTP v 1.x)
- . , .
- , , .
( , , JS).
. , . . , font-swap ( , ). , LightHouse .
. link/preload:
<link rel="preload" href="best_font_ever.otf" as="font" type="font/otf" crossorigin="anonymus">
, fast3g (, ). , . , . , UI - .
, :
500-850ms . , "" .
7,
defer (- page speed LightHouse ), , , .
, (0.5 1 - index.html) ( 480ms 1700ms), 500-800ms . , .
():

, .
, :
- ( )
- Brotli, gzip.
- HTTP2.0.
Jeff Cooper .
. ? . . // ( , ). - Google latency 100-400ms, 0.2%-0.6% ( ). CloudFlare , 2.4ms 3.3ms 0.4%, . . , , .
!