---
title: JavascriptOncePerFile
description: Identifies files that contain more than one JavaScript tag.
source_url:
  html: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/javascript-once-per-file
  md: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/javascript-once-per-file.md
api_name: liquid
---

# JavascriptOncePerFile

Identifies files that contain more than one `{% javascript %}` tag. Theme Check reports the second and later JavaScript tags because `{% javascript %}` can appear only once per file.

Each section or block file should keep its scoped JavaScript in a single JavaScript tag.

***

## Examples

The following examples contain code snippets that either fail or pass this check.

### ✗ Fail

In the following example, `sections/hero.liquid` contains two `{% javascript %}` tags:

```liquid
{% javascript %}
customElements.define('hero-banner', HeroBanner);
{% endjavascript %}


{% javascript %}
customElements.define('hero-video', HeroVideo);
{% endjavascript %}
```

### ✓ Pass

In the following example, `sections/hero.liquid` contains one `{% javascript %}` tag:

```liquid
{% javascript %}
customElements.define('hero-banner', HeroBanner);
customElements.define('hero-video', HeroVideo);
{% endjavascript %}
```

***

## Options

The following example contains the default configuration for this check:

```yaml
JavascriptOncePerFile:
  enabled: true
  severity: error
```

| Parameter | Description |
| - | - |
| `enabled` | Whether this check is enabled. |
| `severity` | The [severity](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#check-severity) of the check. |

***

## Disabling this check

Disabling this check isn't recommended. If you can't avoid violating the rule, then you should disable the check using the [comment syntax](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#disable-checks-using-liquid-comments). This ensures that you intentionally disable the check for each instance.

```liquid
{% # theme-check-disable JavascriptOncePerFile %}
{% javascript %}
customElements.define('hero-banner', HeroBanner);
{% endjavascript %}


{% javascript %}
customElements.define('hero-video', HeroVideo);
{% endjavascript %}
{% # theme-check-enable JavascriptOncePerFile %}
```

***
