Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fasten app loads #17442

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/suite-build/configs/web.webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { FLAGS, routes } from '@suite-common/suite-config';
import { assetPrefix, isDev } from '../utils/env';
import { getPathForProject } from '../utils/path';

const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin');

const baseDir = getPathForProject('web');
const config: webpack.Configuration = {
target: 'browserslist',
Expand Down Expand Up @@ -74,6 +76,13 @@ const config: webpack.Configuration = {
/@trezor\/connect$/,
'@trezor/connect-web/src/module',
),
new PreloadWebpackPlugin({
rel: 'preconnect',
include: 'asyncChunks',
// NOTE: only prefetch js files
fileWhitelist: [/\.js$/],
fileBlacklist: [/_svg\.js$/, /date-fns/, /json\.js/, /suite-data/],
}),
...(!isDev ? [new CssMinimizerPlugin()] : []),
],
};
Expand Down
1 change: 1 addition & 0 deletions packages/suite-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@suite-common/suite-config": "workspace:*",
"@trezor/bundler-security": "workspace:*",
"@trezor/suite": "workspace:*",
"@vue/preload-webpack-plugin": "^2.0.0",
"babel-loader": "^9.1.3",
"babel-plugin-styled-components": "^2.1.4",
"copy-webpack-plugin": "^12.0.2",
Expand Down
7 changes: 3 additions & 4 deletions packages/suite-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
* After the div is added, MutationObserver detects the change and adds React app to the DOM.
*/

import { init } from './Main';

const observer = new MutationObserver(() => {
const appElement = document.getElementById('app');
if (appElement) {
observer.disconnect();

import(/* webpackChunkName: "app" */ './Main')
.then(comp => comp.init(appElement))
.catch(err => console.error(err)); // Fatal error
init(appElement);
}
});

Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12348,6 +12348,7 @@ __metadata:
"@types/node-fetch": "npm:^2.6.12"
"@types/webpack-bundle-analyzer": "npm:^4.7.0"
"@types/webpack-plugin-serve": "npm:^1.4.6"
"@vue/preload-webpack-plugin": "npm:^2.0.0"
babel-loader: "npm:^9.1.3"
babel-plugin-styled-components: "npm:^2.1.4"
copy-webpack-plugin: "npm:^12.0.2"
Expand Down Expand Up @@ -14734,6 +14735,16 @@ __metadata:
languageName: node
linkType: hard

"@vue/preload-webpack-plugin@npm:^2.0.0":
version: 2.0.0
resolution: "@vue/preload-webpack-plugin@npm:2.0.0"
peerDependencies:
html-webpack-plugin: ^5.0.0 || ^4.5.1
webpack: ^5.20.0 || ^4.1.0
checksum: 10/ddaf1542b2cdece5619eb836c96cc177153b8b1a55833d279358d7042d869e916b461e0fc7e8372504a479b8b8c135885b10738bb9a241c5ae542099deef6341
languageName: node
linkType: hard

"@vue/shared@npm:3.4.27":
version: 3.4.27
resolution: "@vue/shared@npm:3.4.27"
Expand Down
Loading