---
name: "[up-asset]"
area: "API"
kind: "HTML attribute"
parent: "up.script module"
url: "https://unpoly.com/api/up-asset"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.script module](https://unpoly.com/api/up.script.md)</nav>

# [up-asset]

Tracks an element as a [frontend asset](https://unpoly.com/learn/handling-asset-changes.md), usually JavaScript and stylesheets.

When [rendering](https://unpoly.com/api/up.render.md), Unpoly compares the assets on the current page with the new assets from the server response. If the assets don't match, an [`up:assets:changed`](https://unpoly.com/api/up:assets:changed.md) event is emitted.

<nav aria-label="Guides">

- [Learn: Reacting to new deployments](https://unpoly.com/learn/handling-asset-changes.md)

</nav>

<nav aria-label="Contents">

#### Contents

- [Default assets](#default-assets)
- [Excluding assets from tracking](#excluding-assets)
- [Tracking additional assets](#including-assets)
- [Tracking the backend version](#tracking-backend-versions)

</nav>

## Default assets {#default-assets}

By default, all remote scripts and stylesheets in the `<head>` are considered assets:

```html
<html>
  <head>
    <link rel="stylesheet" href="/assets/frontend-5f3aa101.css">
    <script src="/assets/frontend-81ba23a9.js"></script>
  </head>
  <body>
    ...
  </body>
</html>
```

Unpoly only tracks assets in the `<head>`. Elements in the `<body>` are never tracked.

[Inline scripts](https://simpledev.io/lesson/inline-script-javascript-1/) and [internal styles](https://www.tutorialspoint.com/How-to-use-internal-CSS-Style-Sheet-in-HTML) are not tracked by default, but you can [include them explicitly](#including-assets).

## Excluding assets from tracking {#excluding-assets}

To _exclude_ an element in the `<head>` from tracking, mark it with an `[up-asset="false"]` attribute:

```html
<script src="/assets/analytics.js" up-asset="false"></script>
```

To exclude assets by default, configure [`up.script.config.noAssetSelectors`](https://unpoly.com/api/up.script.config.md#config.noAssetSelectors).

## Tracking additional assets {#including-assets}

To track additional assets in the `<head>`, mark them with an `[up-asset]` attribute.

For example, [inline scripts](https://simpledev.io/lesson/inline-script-javascript-1/) are not tracked by default, but you can include them explicitly:

```html
<script up-asset>
  window.SALE_START = new Date('2024-05-01')
</script>
```

Only elements in the `<head>` can be matched this way.

To track additional assets by default, configure [`up.script.config.assetSelectors`](https://unpoly.com/api/up.script.config.md#config.assetSelectors).

## Tracking the backend version {#tracking-backend-versions}

To detect a new deployment of your _backend_ code, consider including the deployed commit hash in a `<meta>` tag.

By marking the `<meta>` tag with `[up-asset]`, it will also emit an [`up:assets:changed`](https://unpoly.com/api/up:assets:changed.md) event when the commit hash changes:

```html
<meta name="backend-version" content="d50c6dd629e9bbc80304e14a6ba99a18c32ba738" up-asset>
```

