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

Re-enable dynamic loading of i18n modules & put our bundle on a diet #76

Open
2 of 4 tasks
sergei-maertens opened this issue Sep 27, 2021 · 2 comments · Fixed by #777, open-formulieren/open-forms#5028 or #781
Open
2 of 4 tasks
Assignees

Comments

@sergei-maertens
Copy link
Member

sergei-maertens commented Sep 27, 2021

The webpack config causes these to be loaded from a relative path to the page where the SDK is embedded, rather than relative to the sdk.js module.

A quick fix right now is to always bundle these files instead of loading them dynamically, but this will make the bundle fatter as we add more translations.

  • Create ESM bundle build
  • Dynamically load message catalogs (Lazy load translations #781)
  • Dynamically import leaflet/map features (should trim the main bundle with ~500kB)
  • Dynamically import appointments code/routes.
@sergei-maertens

This comment has been minimized.

@sergei-maertens
Copy link
Member Author

We can't do it with Vite and UMD build - everything is inlined there, but going the ESM route is probably viable! And there's a graceful fallback option.

@sergei-maertens sergei-maertens changed the title Re-enable dynamic loading of i18n modules Re-enable dynamic loading of i18n modules & put our bundle on a diet Jan 15, 2025
@sergei-maertens sergei-maertens moved this from Todo to In Progress in Development Jan 21, 2025
sergei-maertens added a commit to open-formulieren/open-forms that referenced this issue Jan 21, 2025
… if the browser supports it

Using module type scripts makes it possible to opt into the benefits
of bundle splitting where only code is loaded that will actually be
used.

This sets up a wrapper entrypoint/script gated behind the type=module
feature of browsers so it's not executed by browsers that don't
natively support modules yet. An extra advantage is that we can pass
all the necessary configuration via data attributes and process them
in our script, meaning we don't need inline scripts and CSP nonces
anymore for this.

Finally, the SDK ESM module is added to the preload list since we are
guaranteed that we'll need it, and we avoid a waterfall when loading
the entrypoint and then dynamically importing the SDK bundle - those
can be fetched in parallel.
sergei-maertens added a commit to open-formulieren/open-forms that referenced this issue Jan 22, 2025
… if the browser supports it

Using module type scripts makes it possible to opt into the benefits
of bundle splitting where only code is loaded that will actually be
used.

This sets up a wrapper entrypoint/script gated behind the type=module
feature of browsers so it's not executed by browsers that don't
natively support modules yet. An extra advantage is that we can pass
all the necessary configuration via data attributes and process them
in our script, meaning we don't need inline scripts and CSP nonces
anymore for this.

Finally, the SDK ESM module is added to the preload list since we are
guaranteed that we'll need it, and we avoid a waterfall when loading
the entrypoint and then dynamically importing the SDK bundle - those
can be fetched in parallel.
sergei-maertens added a commit to open-formulieren/open-forms that referenced this issue Jan 22, 2025
… if the browser supports it

Using module type scripts makes it possible to opt into the benefits
of bundle splitting where only code is loaded that will actually be
used.

This sets up a wrapper entrypoint/script gated behind the type=module
feature of browsers so it's not executed by browsers that don't
natively support modules yet. An extra advantage is that we can pass
all the necessary configuration via data attributes and process them
in our script, meaning we don't need inline scripts and CSP nonces
anymore for this.

Finally, the SDK ESM module is added to the preload list since we are
guaranteed that we'll need it, and we avoid a waterfall when loading
the entrypoint and then dynamically importing the SDK bundle - those
can be fetched in parallel.
@github-project-automation github-project-automation bot moved this from In Progress to Done in Development Jan 22, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in Development Jan 22, 2025
sergei-maertens added a commit to open-formulieren/open-forms that referenced this issue Jan 22, 2025
… if the browser supports it

Using module type scripts makes it possible to opt into the benefits
of bundle splitting where only code is loaded that will actually be
used.

This sets up a wrapper entrypoint/script gated behind the type=module
feature of browsers so it's not executed by browsers that don't
natively support modules yet. An extra advantage is that we can pass
all the necessary configuration via data attributes and process them
in our script, meaning we don't need inline scripts and CSP nonces
anymore for this.

Finally, the SDK ESM module is added to the preload list since we are
guaranteed that we'll need it, and we avoid a waterfall when loading
the entrypoint and then dynamically importing the SDK bundle - those
can be fetched in parallel.
@github-project-automation github-project-automation bot moved this from In Progress to Done in Development Jan 22, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in Development Jan 22, 2025
sergei-maertens added a commit that referenced this issue Jan 22, 2025
This should make the main bundle smaller and ensure we only fetch the
translations that will actually be used.
sergei-maertens added a commit that referenced this issue Jan 22, 2025
This should make the main bundle smaller and ensure we only fetch the
translations that will actually be used.
@github-project-automation github-project-automation bot moved this from In Progress to Done in Development Jan 23, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in Development Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment