---
title: Using code minification and compression
related:
  - https://docs.kentico.com/k10/configuring-kentico/optimizing-website-performance.md
  - https://docs.kentico.com/k10/developing-websites/designing-websites-using-css.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

An important factor that influences the performance of a website is the size of code resources, which are requested by client browsers when rendering pages. The most significant among these are CSS stylesheets and JavaScript source files, which can in some cases reach sizes that considerably impact page load time.

Kentico provides two types of built‑in functionality that help optimize the performance of requests for CSS and JavaScript resources:

| Code minification    | Removes all unnecessary characters from the code that are not required by the browser to correctly process the resource. This includes white spaces, line break characters, comments, bookmarks etc.<br>Minified resources behave in exactly the same way as the original. Browsers can immediately handle minified resources without any additional steps.<br>**Note**:<br>Minified code is difficult to read (for humans) and is therefore unsuitable for debugging.<br>JavaScript minification does not work on instances running on [Microsoft Azure Cloud Services](https://docs.kentico.com/k10/running-kentico-on-microsoft-azure/running-kentico-in-azure-cloud-services.md) (even if the corresponding setting is enabled). |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Resource compression | Reduces the size of resources by encoding their data. To apply compression, you must also enable minification for resources of the given type.<br>When a client browser receives a compressed resource, it must first decompress the data. All browsers officially supported by Kentico should be able to correctly decompress files. In cases where the client cannot process compressed data, the system automatically sends the unmodified resource instead.                                                                                                                                                                                                                                                                      |

You can enable or disable code minification and compression globally for all sites in **Settings -> System -> Performance**, through the settings in the **Resources** category.

Reducing the size of requested resources saves bandwidth and improves the response time of your website. Minification can decrease the size of a resource by approximately 20–40%, depending on the code of the given object. If compression is also used, resources can be reduced to roughly 30% of their original size.

> **Note:** **Note**: The reductions only apply to resources stored individually in the file system or database. Inline code inserted into the HTML markup of pages is not affected.

The minification and compression process slightly increases the server CPU load and adds a short delay to resource requests. To counter this issue, the system uses server-side caching for resource files:

- Minification/compression only occurs once when a resource is requested for the first time (the cache stores the result).
- On subsequent client requests, the system provides the transformed version of the resource from the cache.
- The cache stores both compressed and uncompressed versions of resources, so the data is readily available even for clients without compression support.
- You can set the number of minutes for which files are cached through the **Cache files (minutes)** setting in **Settings -> System -> Performance**.

Additionally, you can use client‑side browser caching for resources (enabled by default). With client caching, browsers only reload resources from the server if the cached data expires or the content of the resource becomes outdated. See [Caching files and resources](https://docs.kentico.com/k10/configuring-kentico/optimizing-website-performance/configuring-caching/caching-files-and-resources.md) to learn how to configure the client-side file caching.

> **Tip:** **Using external preprocessing tools**
>
> You can also use external preprocessing tools (LESS, Grunt tasks, ...) and store your CSS and JS files as static physical files. You lose the ability to edit the files within Kentico UI, but avoid having the system to compile the resources with the first request each time the cache expires.

## Requesting minified resources

Compression and minification is automatically ensured by the **\~/CMSPages/GetResource.ashx** handler, which manages resource requests according to the specified settings. If minification is enabled, CSS and JavaScript requests generated by the system use this handler.

You can manually load resources in your code by using the following URL parameters with the handler:

- **stylesheetname** - used to request a [CSS stylesheet](https://docs.kentico.com/k10/developing-websites/designing-websites-using-css.md) from the database. The code name of the requested stylesheet must be entered as the value of the parameter.\
  Link example:\
  __
- **\_transformations, \_layouts, \_templates, \_devicelayouts, \_webparts, \_webpartlayouts, \_containers** - used to request the internal stylesheets of the corresponding type of page component. The object ID values of the given components must be entered as the value of the parameter, separated by semicolons (if multiple component stylesheets are requested). See [Adding CSS to page components](https://docs.kentico.com/k10/developing-websites/designing-websites-using-css/adding-css-to-page-components.md).\
  Link examples:\
  _\&#xA;_
- **stylesheetfile** - used to request static CSS resources from the file system. The relative path of the requested .css file must be entered into the parameter.\
  Lnk example:\
  __
- **scriptfile** - used to request static JavaScript resources from the file system. The relative path of the requested .js file must be entered into the parameter.\
  Link example:\
  __

> **Info:** **Resource requests with minification disabled**
>
> If minification is disabled, the system generates requests with a direct URL (for JavaScript files) or using the **\~/CMSPages/GetCSS.aspx** system page (for CSS stylesheets).
>
> Requests in this URL format are always supported, but they do not perform minification or compression of resources.

## Enabling compression of page output

You can configure the system to compress the HTML output code of all pages rendered by Kentico.

> **Info:** **Note**: Output compression requires compliance from client browsers. Browsers that do not support compression always download uncompressed page output.

1. Go to **Settings -> System -> Performance**.
2. Check **Enable output compression**.
3. Click **Save**.

The setting applies globally for all sites in the system.
