As sprints go on, our CMS project becomes a huge project. But this application responses very slow due to very large app chunk and vendor chunk, and it might irritate clients because of the long time waiting for static bundle responding.
There are two problems in our CMS:
vue-code-diff
is a large and rarely used dependency only for event change history page, then it's a worst strategy to add it in vendor chunk, since only user who invites this page requires this package.There are few strategies to resolve the struggle below.
Not all routes are required in the initial app chunk, we should minimize bundle size for client as possible.
underscore
with ramda
and lodash-es
Our project is based on underscore
and ramda
as util functions. But in fact, only little underscore
functions are used. I tried monolitic import underscore
to gain small bundle size but failed. Finally, I replace almost 95% of unserscore
functions with ramda
functions, as for some functions which are not pure-function such asthrottle
and uniqueId
, I used lodash-es
.
To decrease vendor size, I drop large and rarely used third party dependencies, and then split vendor to ui and base chunk to make sure all chunks are as tiny as possible.
Add two cutom plugins BoostrapVue
and BootstrapVueIcons
to import only used components.
Since we don't use any locale format date string for usage. Drop all locales in momentjs
.
Max chunk size was 7.69 MB (uncompressed).
Many unused pages were involved in app chunk.
Many unused third party dependencies were involved in vendor chunk.
User paid about 7~11 seconds for the page response.
Max chunk size is 2.54 MB (uncompressed).
Only core business logic are invloved in app chunk, and not all pages included in the initial bundle.
Only core third party dependencies are involved in vendor chunk, as for user requires a rarely dependency, he needs an additional network request for it.
Besides, chunks seems more average after code splitting.
User pays about 1~4 seconds for the page response.
Here are some tips for refactoring our CMS after all these changes:
momentjs
with dayjs
for better bundle size.gzip
for js
, css
, html
resource for web server, we have the follow up solution in this article.ckeditor4
only for required page.ec-lib
and bootstrap-vue
for component unit test as possible to reduce unit test time./pages
from /components
to improve readability of project.Work
JavaScript
Vue
Vue2