diff --git a/crates/templates/src/functions.rs b/crates/templates/src/functions.rs index 2ca7b12f6..35bac44a9 100644 --- a/crates/templates/src/functions.rs +++ b/crates/templates/src/functions.rs @@ -522,6 +522,19 @@ impl Object for IncludeAsset { } } + mas_spa::FileType::Json => { + // When a JSON is included at the top level (a translation), we preload it + let integrity = main.integrity_attr(); + let src = main.src(assets_base); + if tracker.mark_preloaded(&src) { + writeln!( + output, + r#""#, + ) + .unwrap(); + } + } + file_type => { return Err(Error::new( ErrorKind::InvalidOperation, @@ -566,7 +579,9 @@ impl Object for IncludeAsset { } mas_spa::FileType::Woff | mas_spa::FileType::Woff2 | mas_spa::FileType::Json => { // Skip pre-loading fonts and JSON (translations) as it will - // lead to many wasted preloads. + // lead to many wasted preloads. For translations, we only + // include them as preload if they are included on the + // top-level } } } diff --git a/templates/app.html b/templates/app.html index 618daed69..d43416f9a 100644 --- a/templates/app.html +++ b/templates/app.html @@ -23,6 +23,8 @@ Please see LICENSE files in the repository root for full details. window.APP_CONFIG = JSON.parse("{{ config | tojson | add_slashes | safe }}"); {{ include_asset('src/entrypoints/main.tsx') | indent(4) | safe }} + {# Pre-load the locale data for the current language #} + {{ include_asset('locales/' ~ lang ~ '.json') | indent(4) | safe }}