How to minify and compress Assets (css,js) when pu...
# help-with-umbraco
m
I want to automatically minify the CSS and JS files in the assets folder when publishing. Is that possible?
s
Perhaps this documentation is what you are looing for? https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-8.0 There are link in the article to Gulp and Webpack, that you might want to take a look at. Also there is an extension for Visual Studio called "Bundler and minifier" that could to the trick for you. https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BundlerMinifier
m
And I guess you can always just go the Vite route like the webcomponents for the back office in umbraco too.. https://skrift.io/issues/vite-and-umbraco-v13/
s
Another option is esbuild
k
Yep it's definitely possible. I highly recommend checking out Web Optimizer (https://www.nuget.org/packages/LigerShark.WebOptimizer.Core/). I've been using it on my most recent Umbraco projects and found it works really well with minimal setup/configuration. It bundles and minifies your CSS and JS files, and it also generates and appends a cache buster string to your file references when the project builds -- so no need to worry about telling clients or QA to "hard refresh" every time you deploy changes. Compared to other tools like Vite, Webpack, or Gulp, Web Optimizer is simpler to set up and integrates easily with .NET and Umbraco. If you’re mostly focused on backend functionality with some basic frontend requirements like bundling and minification, it’s a solid choice. On the other hand, tools like Vite or Webpack might be better if you’re working with SPA frameworks (React, Vue, etc.) or need advanced features like hot module replacement.
68 Views