Skip to content

Code splitting for FT.com #169

@i-like-robots

Description

@i-like-robots

This issue is a catch-all for our discussions around developing a code splitting strategy for delivering JavaScript to our users of FT.com.

The reason we wish to enable code-splitting is to increase the cache-ability of our client-side code. JavaScript kilobytes are the most expensive so leveraging caching more is a key component of Anvil's performance strategy and meeting our success metric of decreasing time to interactive.

By splitting our JavaScript code effectively this should improve caching by:

  • Decreasing the number of times we bust the cache - small changes to one piece of code should not force a user to re-download everything.
  • Enable increased code reuse between our user-facing microservices - if the front page, stream pages, and article pages all need o-date@3.0.1, then we should aim to reuse that package across all of them. A user journey across these apps will be faster with assets ready in a warm cache.

Webpack offers very powerful code splitting tools which should have the flexibility for us to build an appropriate strategy on top of. We have a basic example of this code splitting feature already which demonstrates how to split all of the npm packages required by a bundle into separate files but this is not an appropriate strategy for FT.com because:

  1. Our apps can have hundreds of separate dependencies. Handling many small files is slower than sending one big bundle (and may limit effective usage of resource hint headers?)
  2. Some of our apps have multiple entry points (usually with the intention of lazy loading them) but we currently lack suitable tooling to reassemble these at runtime if split into pieces.

There are also some other things to consider:

  • One a limitation of Webpack's runtime (a small module used when leveraging code splitting which can track each dependency loaded in the browser) is that it cannot dynamically load scripts. Therefore to initialise an app we must first send all of the scripts required to the browser. This is not necessarily a bad thing as it enables the use of resource hints and downloading scripts in parallel but it could also mean sending too much, decreasing the effectiveness of lazy loading.

  • The limitations of the Webpack runtime can be avoided by using techniques such as dynamic import() but this technique can actually increase the time it takes for scripts to be executed as the pieces may need to be parsed and executed in series in order to build a complete dependency tree. It is also unclear how this may be retrofitted to existing code.

  • Our apps build their own assets and are not aware of the asset graph of other apps. In order for applications to reuse any scripts they must generate files with the same name and contents.

So, please submit your ideas for a JavaScript code splitting strategy which:

  • Enables reuse of shared code across multiple user-facing microservices
  • Balances the number of files against the time required downloading and processing them
  • Does not prevent multiple entry points and/or lazy loading code
  • Enables effective use of resource hints and parallel downloads

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions