Cache Busting with CSS Isolation and a component library - Blazor Webasm
See original GitHub issueHi,
Firstly apologies, this may be more of a question/feature request than a bug, but I wasn’t quite sure where to put it.
I have a ASP.Net hosted Blazor web assembly application. I’m trying to cache bust the JS and CSS files in my project because I’m struggling to get the browser to refresh them when I redeploy. In desktop I can refresh with CTRL-F5, but this is not so easy in mobile browsers and my application can go screwy if it doesn’t have the latest files and obviously end users will struggle to clear the cache.
I have read the two similar issues: #27047 and #27966 and have implemented my own cache busting on the ASP.Net side by adding a version in the URL as a query parameter. I did this by hosting Blazor in razor page and using a function to add a version where required.
This seems to work OK, but I have a component library project in my solution and I’m not sure how I can do the same for the CSS generated by CSS isolation in the component library (“_content/ClassLib/ClassLib.bundle.scp.css”),
Currently this is included “automatically” by using an @import statement at the top of the main project;s ‘bundled’ CSS which I don’t seem to have any control of. I believe my 2 options are:
- Include a version on the
@import, however this is created by the Blazor tooling so as far as I know I have no way of doing it. - Stop Blazor generating the
@importstatement and include it myself in the hosting razor page as per all the other CSS.
Can you advise if either option is possible or you have any other suggestion? In regard to option 2 I’ve found the DisableScopedCssBundling property, but I presume this stops the CSS being generated at all?
Thanks in advance! LJ
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
That is correct, we either produce a bundle or not.
The extensibility that we offer is that you can disable or built-in bundling an create your own MSBuild task to handle the bundling process yourself, we don’t plan to offer any sort of “partial” bundling, since it complicates the implementation a lot and we haven’t heard a significant demand for it.
There’s no problem as long as you do it right after the file has been bundled. You can use MSBuild structured log viewer to see where the file is generated and hook your own target to run after that.
@LaughingJohn thanks for contacting us.
There are two things you can do here: