Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fingerprinted file name for microfrontend entrypoint bundle to enable caching it #2

Draft
wants to merge 1 commit into
base: recording
Choose a base branch
from

Conversation

xkons
Copy link
Collaborator

@xkons xkons commented Jan 12, 2023

This PR adds caching for the micro frontend bundles on top of #1

To make our our micro frontends cacheable, we adjust their build step to generate the main.js entrypoint file with a content based hash in the filename. This can easily be done using the Angular CLI. Then we just need to store the information of this filename in a file on the static storage (e.g. netlify) of the micro frontend so that we can load it. This new frontend-meta.json just weighs 1kB and will not be cached, so that it always contains the latest hashed entrypoint file name.

When loading a micro frontend, we now first load the frontend-meta.json and then the fingerprinted main.<hash>.js file. The latter will be cached by the browser. So until we deploy a new version of a micro frontend, the browser of our users will not have to download the roughly 500kB to open a page with that micro frontend anymore, but it is directly loaded from the users cache stored on their computer.

Important to know: The frontend-meta.json should never be cached by your clients to ensure that they always get the latest entrypoint bundle of your microfrontend.

This PR enables us to add a caching header to the response that fetches the entrypoint bundle of a microfrontend like.

Since the file name of the entrypoint bundle contains a md5 hash based on the content of the file, we know that if a bundle with the same name has been fetched by the browser, it is unchanged.

E.g. caching for one year:
Cache-Control: max-age=31536000

The main.js file name we used before did not allow for caching, while still ensuring that all customers always get the latest micro frontend code.

Enables us to add a caching header to the response
that fetches the entrypoint bundle of a microfrontend like.

Since the file name of the entrypoint bundle contains a md5 hash
based on the content of the file, we know that if a bundle with the same name
has been fetched by the browser, it is unchanged.

E.g. caching for one year:
Cache-Control: max-age=31536000

The main.js file name we used before did not allow for caching,
while still ensuring that all customers always get the latest micro frontend code.
@xkons xkons force-pushed the caching-entrypoint-bundles branch from cd9fa08 to aa70d57 Compare January 12, 2023 15:45
@xkons xkons changed the title Use fingerprinted file name for microfrontend entrypoint bundle Use fingerprinted file name for microfrontend entrypoint bundle to enable caching it Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant