Skip to content

NUglify

Makes the files your site ships smaller. Nothing to install, nothing to download.

Add it

Terminal
dotnet add package Nacara.Plugin.Assets.Nuglify --prerelease

Ask for the formats you want:

Site.create "My library"
|> Markdown.register
|> Theme.register theme
|> Nuglify.minifyHtml
|> Nuglify.minifyJs

On this site that takes the HTML down by 2.5% and the JavaScript by half, both measured after gzip - the scripts are where the win is.

One tool per format

Each of these claims one kind of file and leaves the others alone. minifyHtml will not touch the CSS in a <style> block or the code in a <script>, so whatever you registered for those handles them, once.

There is a Nuglify.minifyCss too. Use it or LightningCss, never both. Lightning CSS compiles as well as minifies, so prefer it for modern CSS.

Is it safe?

Yes, with the defaults. Your pages read the same, your scripts still work, and anything a browser or your markup calls by name keeps that name.

Two options can change that, so both are off:

  • RemoveOptionalTags drops </body> and friends. Valid HTML, but tools that look for </body> to insert something - Nacara's dev server included - stop finding it.
  • Turning off KeepOneSpace lets words run together where a line break used to separate them.

Turn either on and read a few pages afterwards.

Options

|> Nuglify.minifyHtmlWith(
    Nuglify.htmlMinifyWhileWatching true
)
HTMLDefaultEffect
CollapseWhitespacetrueCollapse runs of whitespace between elements
KeepOneSpacetrueLeave one space where a run was, so nothing the reader sees moves
RemoveCommentstrueDrop HTML comments
RemoveAttributeQuotesfalseDrop quotes from attribute values that do not need them
RemoveOptionalTagsfalseDrop end tags HTML5 allows you to leave out, such as </body>
MinifyWhileWatchingfalseMinify during watch builds too
JavaScriptDefaultEffect
ShortenNamestrueShorten local variable names; anything reachable from outside keeps its own
KeepLicenceCommentstrueKeep /*! … */ comments, where a licence lives
MinifyWhileWatchingfalseMinify during watch builds too
CSSDefaultEffect
KeepLicenceCommentstrueKeep /*! … */ comments, where a licence lives
MinifyWhileWatchingfalseMinify during watch builds too

Reference

Every function and option of it, signature by signature: Nuglify.

Edit this page