# 0043. One jQuery, and every script deferred

- **Status:** Accepted
- **Date:** 2026-09-24

## Context

Every page carried jQuery more than once: each Encore entry bundled its own copy and Yii's `JqueryAsset`
published another, unminified. The site's widgets and `yii.activeForm.js` ran against different jQuery objects.
No script was `defer`.

## Decision

As Molino (its ADR 0046 and 0053): `resources/js/jquery-global.js` puts jQuery on the window first in `common`
and `admin`; `webpack.config.js` makes `jquery` an external; `config/components/assetManager.php` switches
`JqueryAsset` off and defers Yii's own assets. Encore bundles are `defer`, and `View::deferReadyScripts()` moves
`POS_READY` / `POS_LOAD` behind `DOMContentLoaded`. lodash, used for four `forEach` calls, is gone.

## Alternatives

- **`splitEntryChunks()`.** Deduplicates everything shared, and changes the `entrypoints.json` contract
  `View::getEntryList()` reads. Left for its own task.
- **`async`.** No order guarantee.

## Consequences

- An inline `<script>` in a view or in the settings embeds cannot assume jQuery exists.
- A `webpack.config.js` change means restarting Encore.
