Increasing the Responsiveness of Web Applications by Introducing Lazy Loading
Published in ASE, 2023
Recommended citation: Alexi Turcotte, Satyajit Gokhale, and Frank Tip. 2023. Increasing the Responsiveness of Web Applications by Introducing Lazy Loading. In 38th IEEE/ACM International Conference on Automated Software Engineering (ASE). Kirchberg, Luxembourg. ACM, New York, NY, USA. 12 pages. http://reallytg.github.io/files/papers/lazifier.pdf
Front-end developers want their applications to con- tain no more code than is needed in order to minimize the amount of time that elapses between visiting a web page and the page becoming responsive. However, front-end code is typically written in JavaScript, the ubiquitous “language of the web”, and tends to rely heavily on third-party packages. While the reuse of packages improves developer productivity, it is notorious for resulting in very large “bloated” applications, resulting in a degraded end-user experience. One way to combat such bloat is to lazily load external packages on an as-needed basis, for which support was added to JavaScript in 2020 when asynchronous, dynamic imports were added to the language standard. Unfortunately, migrating existing projects to take advantage of this feature is nontrivial, as the code changes required to introduce asynchrony may involve complex, non-local transformations.
In this work, we propose an approach for automatically introducing lazy loading of third-party packages in JavaScript applications. Our approach relies on static analysis to identify external packages that can be loaded lazily and generates the code transformations required to lazily load those packages. Since the static analysis is unsound, these transformations are presented as suggestions that programmers should review and test carefully. We implement this approach in a tool called Lazifier, and evaluate Lazifier on 10 open-source front-end JavaScript applications, showing that each application was successfully refactored, reducing initial application size and load times in all cases. On average, for these applications, Lazifier reduces initial application size by 36.2%, initial load time by 29.7%, and unsoundness did not arise in any of these applications.