wikimedia / wikipedia-preview

https://wikimedia.github.io/wikipedia-preview/main
MIT License
64 stars 22 forks source link

Analyse and reduce the bundle size #137

Open santhoshtr opened 3 years ago

santhoshtr commented 3 years ago

Currently the https://wikimedia.github.io/wikipedia-preview/demo/script/wikipedia-preview.production.js is about 142KB. Out of 142KB, about 136KB is dompurify library.

I see that DOMPurify is used for sanitizing the content from wikipedia. May be we need to check the trust model for the content too. If we can avoid bundling dompurify, then wikipedia-preview is just 5.4KB uncompressed.

hueitan commented 3 years ago

This is how it looks like npm run wba, and we can also lower the bundle size if we take care of the i18n files in this task

image

santhoshtr commented 3 years ago

To clarify, I was talking about https://wikimedia.github.io/wikipedia-preview/demo/script/wikipedia-preview.production.js file. Its big share is dompurify. For example in the web page, https://diff.wikimedia.org/2021/07/29/new-wikipedia-preview-feature-provides-context-from-wikipedia-across-the-web/ this is one of the biggest javascript assets.

stephanebisson commented 3 years ago

@santhoshtr I'm curious about how you got those numbers (136k / 124k) from that production file. The only way I know how to measure those things is with Webpack bundle analyzer (see Huei's screenshot).

That said, I would also like to remove DOMPurify.

akudiaku commented 2 months ago

https://github.com/wikimedia/wikipedia-preview/actions/runs/10883706041/job/30197431268#step:5:1

hueitan commented 1 day ago

This is the new bundle size visualization after this https://github.com/wikimedia/wikipedia-preview/pull/177, we have plan to remove the purify.js and have the i18n as the separate https://github.com/wikimedia/wikipedia-preview/pull/222

image