Minifier — API Documentation

Back to Minifier

Overview

This page documents the public Minifier APIs available at /api/public/*. These endpoints accept JSON POST bodies and return a BaseResponse JSON envelope on success or error. ZIP download endpoints return application/zip on success and JSON BaseResponse on error.

{
  "serverTime": 0,
  "errorMessage": null,
  "payload": { /* ... */ }
}

Public routes do not require anti-forgery tokens. If you are integrating from the UI within this application, protected UI routes under /api/* exist but are intended for in-browser usage only.

Public Endpoints

  • POST /api/public/css-minifier/minify — CSS minify (JSON)
  • POST /api/public/js-minifier/minify — JS minify (JSON)
  • POST /api/public/css-minifier/download-zip — returns ZIP containing styles.min.css
  • POST /api/public/js-minifier/download-zip — returns ZIP containing scripts.min.js

CSS Minify

POST JSON to /api/public/css-minifier/minify. Request model is shown in the example.

{
  "InputCss": "...",
  "KeepImportantComments": true,
  "ColorNames": 0,
  "AbbreviateHexColor": true,
  "MinifyExpressions": true,
  "CssType": 0,
  "RemoveEmptyBlocks": true,
  "FixIE8Fonts": true,
  "DecodeEscapes": true,
  "ExcludeVendorPrefixes": ["ms","webkit"]
}

On success, payload contains outputCss, sizes and optional errors/warnings. On error, the server returns a non-2xx status and sets errorMessage with payload as null.

JS Minify

POST JSON to /api/public/js-minifier/minify. Request model supports many advanced options that map to NUglify CodeSettings. Example minimal request shown.

{
  "InputJs": "console.log('hello');",
  "MinifyCode": true,
  "EvalTreatment": 0,
  "InlineSafeStrings": true,
  "MacSafariQuirks": true,
  "PreserveImportantComments": true,
  "StripDebugStatements": true
}

Note: enum properties must be sent as numeric values from the client. The UI provides numeric select values for these.

Download ZIP

Both CSS and JS ZIP endpoints accept the same payloads as the corresponding minify endpoints and return an application/zip file with the minified artifact.

On error, ZIP endpoints return JSON BaseResponse with errorMessage set and payload null.

Advanced Settings

The UI exposes advanced settings for both CSS and JS. These map directly to NUglify settings (see the UI for default values). The JS settings default to the values used by new CodeSettings().

cURL Examples

Public endpoints do not require an anti-forgery token. Example CSS minify and JS minify shown.

curl -X POST https://localhost:5001/api/public/css-minifier/minify \
  -H "Content-Type: application/json" \
  -d '{"InputCss":"body { color: red; }","KeepImportantComments":false,"ColorNames":0}'

Example JS minify:

curl -X POST https://localhost:5001/api/public/js-minifier/minify \
  -H "Content-Type: application/json" \
  -d '{"InputJs":"console.log(1);","MinifyCode":true}'

UI (protected) endpoints require the anti-forgery token header RequestVerificationToken.

Security / Notes

  • Max input size: InputCss and InputJs are limited to 1,048,576 bytes (1 MiB) (UTF-8 byte count).
  • Enum values: enum properties must be valid numeric values (e.g. EvalTreatment, Format, LocalRenaming, ScriptVersion, SourceMode).
  • Vendor prefix list limits: ExcludeVendorPrefixes supports up to 50 entries and each entry must be non-empty and at most 64 characters.
  • Large JS fields: RenamePairs, NoAutoRenameList, KnownGlobalNamesList, and DebugLookupList are limited to 65,536 characters each.
  • RenamePairs format: must be comma-separated source=target pairs (e.g. longName=a, other=b).
  • ZIP error behavior: on failure ZIP endpoints return JSON with errorMessage set; clients should inspect the response when the HTTP status is non-2xx.
  • Production advice: public endpoints are unauthenticated — consider adding rate limiting, API keys, or quotas when exposing them publicly.

Usage Details

Responses use the BaseResponse envelope. Check the HTTP status and then read errorMessage (string) and payload (object) to determine success.

{ "serverTime": 1676496000, "errorMessage": null, "payload": { /* minify result */ } }

On error the envelope will have errorMessage set and payload null. ZIP endpoints return binary on success; when the status is non-2xx, the body is a JSON error envelope.