Skip to content

Preload all js bundles required for a specific route #26484

Description

@nathan-nusign

Which @angular/* package(s) are relevant/related to the feature request?

platform-server

Description

When loading a route, the browser downloads the HTML file, then the main.js file, and only after that it loads other files that are required by the main js file, for example, a component that is lazy loaded using loadComponent in the router.

Proposed solution

I think there is an opportunity to use the fact that SSR already had to render the page, so should know which bundles are required for this route. If the bundles can be identified, then they could be preloaded (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload) so that the browser can download all of the js files that are required to render the page at the same.

Alternatives considered

N/A

Activity

  1. added 20 commits that reference this issue on Nov 21, 2024
    95f2b19
    9b4c01a
    a84ba7d
    6d62cb0
    be14f78
    913f62e
    1eb3c20
    4cb8cf5
    18d0d35
    0713e4c
    5894bb9
    4c645a0
    97607df
    8f4b6ee
    80c7baa
    212ad1a
    d78d2ad
    7829488
    9524778
    52500d9
  2. added 4 commits that reference this issue on Dec 3, 2024
    59e3579
    86e0be8
    509feb7
    b15ae1f
  3. added
    feature: in backlogFeature request for which voting has completed and is now in the backlog
    and removed
    feature: under considerationFeature request for which voting has completed and the request is now under consideration
    on Dec 5, 2024
  4. self-assigned this
    on Dec 5, 2024
  5. added 3 commits that reference this issue on Dec 6, 2024
    4281f58
    572c1a0
    31ff83a
  6. added a commit that references this issue on Dec 10, 2024
    8d7a51d
  7. naveedahmed1 commented on Dec 11, 2024

    @naveedahmed1

    @alan-agius4 what if in case of server side, it also create HTTP 103 Early Hints while generating modulepreload links? These could be added to ResponseInit as early hints headers.

  8. alan-agius4 commented on Dec 11, 2024

    @alan-agius4
    Collaborator

    Early Hints are something we want to explore further. However, we need to be cautious about adding Early Hints as similar to modulepreload links they can negatively impact performance.

    For example, in the case of SSR, we may prefer prioritizing the download of images over JavaScript to avoid conflicts that could impact Core Web Vitals.

  9. naveedahmed1 commented on Dec 11, 2024

    @naveedahmed1

    Have you done any experiments with early hints? In our case, using our custom implementation we add early hints for:

    stylesheet
    eager loaded images
    polyfills
    main
    modulepreload

    And it in fact it improved the CWV. Whats your observation?

  10. angular-automatic-lock-bot commented on Jan 11, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions