Hi! We have a project with a BlazorWASM UI with LeptonX. When the app starts, it sends a request to https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap to get the fonts.
Since some of our users don't have internet access, they get an error at this point. So, I downloaded and saved the fonts to MyProjectBlazorClient/wwwroot/fonts/inter and added @font-faces to main.css to store and use them locally. Now they're being fetched locally, but the internet request is still being sent.
I searched and found that in the font-bundle.css file, which is located at _content/Volo.Abp.AspNetCore.Components.Web.LeptonXTheme/side-menu/css there's a line: @import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap"); , which is what sends the request to get the fonts.
My question is: What can I do to use only local fonts? Are there ready-made solutions for this?
2 Answer(s)
-
0
- Don’t edit
_content/Volo.Abp.AspNetCore.Components.Web.LeptonXTheme/.../font-bundle.css(it comes from the NuGet package and will be regenerated/overwritten). - Instead, override the theme’s
font-bundle.csswith your own file (same virtual path) so the@import url("https://fonts.googleapis.com/...")line is never shipped to the browser.
Step-by-step
- Create a local replacement file in your Blazor WASM client project:
MyProjectBlazorClient/wwwroot/_content/Volo.Abp.AspNetCore.Components.Web.LeptonXTheme/side-menu/css/font-bundle.cssPut your local
@font-facedeclarations there (pointing to your local.woff2/.wofffiles underwwwroot/fonts/inter/...) and do not include any@importto Google Fonts.Example skeleton (adjust paths to your real files):
/* MyProjectBlazorClient/wwwroot/_content/Volo.Abp.AspNetCore.Components.Web.LeptonXTheme/side-menu/css/font-bundle.css */ @font-face { font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("/fonts/inter/Inter-VariableFont.woff2") format("woff2"); } /* add italic, opsz variants as needed... */- (Optional but recommended) Also override RTL if your app uses RTL:
MyProjectBlazorClient/wwwroot/_content/Volo.Abp.AspNetCore.Components.Web.LeptonXTheme/side-menu/css/font-bundle.rtl.css(Usually it can be identical to
font-bundle.css.)- Rebuild and redeploy. The browser will still request
font-bundle.css, but it will now be served from your app and will not contain the Google Fonts import, so no request tofonts.googleapis.comwill be triggered.
This works because ABP serves static files from your app’s
wwwroot, and a file placed under the exact same_content/{packageId}/...path effectively overrides the packaged static resource at runtime.
Sources (verified)
- https://abp.io/docs/latest/framework/ui/mvc-razor-pages/bundling-minification#bundle-contributors
- https://abp.io/docs/latest/release-info/migration-guides/abp-7-0
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
- Don’t edit
-
0
Hi,
The
font-bundle.cssin LeptonX Lite theme contains an@importto Google Fonts, and there's no built-in option to disable it. You can customize the style bundle contributor to replace it with either local fonts or a different online font provider.Step 1: Create your font CSS file (e.g.
wwwroot/fonts/my-fonts.css).For local fonts (recommended for offline environments):
@font-face { font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("InterVariable.woff2") format("woff2"); } @font-face { font-family: "Inter"; font-style: italic; font-weight: 100 900; font-display: swap; src: url("InterVariable-Italic.woff2") format("woff2"); }You can download the Inter font files from https://github.com/rsms/inter/releases and place them alongside this CSS file.
Or if you want to use a different online font (e.g. Bunny Fonts, Adobe Fonts, etc.), you can simply use an
@importpointing to that provider instead.Step 2: Create a custom style contributor to replace the
font-bundle.css:using Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class MyBlazorStyleContributor : BundleContributor { public override void ConfigureBundle(BundleConfigurationContext context) { // Remove the Google Fonts import context.Files.RemoveAll( f => f.Contains("font-bundle") ); // Add your font CSS instead context.Files.AddIfNotContains("/fonts/my-fonts.css"); } }Step 3: Register the contributor in your module class:
Configure<AbpBundlingOptions>(options => { options.StyleBundles.Configure( BlazorLeptonXLiteThemeBundles.Styles.Global, bundle => { bundle.AddContributors<MyBlazorStyleContributor>(); } ); });The default
BlazorLeptonXLiteThemeStyleContributorstill runs first and adds everything, then your contributor removesfont-bundle.cssand adds your font file instead. Since some of your users don't have internet access, local fonts would be the best approach for your scenario.Thanks