Adding static files
Blazor can use static files, such as images, CSS, and JavaScript. If we put our files in the wwwroot
folder, they will automatically be exposed to the internet and accessible from the root of our site. The nice thing about Blazor is that we can do the same with a library, it is super easy to distribute static files within a library.
At work, we share components between all of our Blazor projects, and the shared library can depend on other libraries as well. We need to add a link to the static file using the _content
folder.
Take a look at this example:
<link rel="stylesheet" href="_content/MyBlog.Shared/MyBlogStyle.min.css" />
The HTML link
tag, rel
, and href
are ordinary HTML tags and attributes, but by adding the URL that starts with _content
, this is telling us that the content we want to access is in another library. The name of the library (assembly name) is followed by, in this case, MyBlog.Shared
, and then the file we...