refactor: migrate inline JS in templates to Joomla Web Asset Manager #175
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
All five admin templates embed hundreds of lines of inline JavaScript directly in PHP files via
<script>tags. Joomla 4+ provides the Web Asset Manager (WAM) for registering and loading JS/CSS assets. Using WAM enables proper dependency management, caching, CSP nonce support, and cleaner template files.Affected templates
tmpl/backups/default.phptmpl/dashboard/default.phptmpl/backup/default.phptmpl/snapshots/default.phptmpl/profile/edit.phpWhat to do
media/com_mokosuitebackup/js/directory structure.jsfiles (e.g.,admin-backups.js,admin-dashboard.js, etc.)joomla.asset.json(or via$wa->registerAndUseScript())$document->addScriptOptions()instead of inline PHP-in-JS<script>blocks from templatesWhy
Inline JS blocks Content-Security-Policy nonce enforcement, prevents browser caching, and makes the 700+ line template files harder to maintain. WAM is the standard Joomla approach and enables all of the above.
Branch created:
feature/175-refactor-migrate-inline-js-in-templates-Confirmed still valid @ 02.56.05 — keep open.
tmpl/snapshots/default.php:351-627is still one large inline<script>block; there is nomedia/com_mokosuitebackup/js/directory. Other templates (backups/dashboard/backup/profile) likewise retain inline JS. No Web Asset Manager migration yet.Started (stable): the component now ships a Web Asset Manager stylesheet —
media/com_mokosuitebackup/css/admin.css+media/joomla.asset.json, a<media>manifest entry, anduseStyle('com_mokosuitebackup.admin')in the profile-edit view (PR #220). This establishes the WAM pattern.Keeping this open for the remaining migration: the large inline
<script>blocks intmpl/snapshots/default.php(and the other templates) still need moving tomedia/com_mokosuitebackup/js/*.jsregistered the same way.