[FEATURE] Conditional asset loading for tile_maps plugin #2

Merged
trokohl merged 1 commit from gert.hammes.ba/tile_maps:main into main 2026-05-15 20:58:21 +02:00
Contributor

Adds a TypoScript constant that controls whether the extension's CSS and JavaScript assets are loaded globally on every page or only on pages that actually render a tile map.

Motivation

Previously, MapCreator.css, jQuery, and MapCreator.js were included on every page of the site via page.includeCSS / page.includeJSFooter, regardless of whether a map was present. This is unnecessary overhead on pages without a map.

Changes

New constant (default 0, fully backward-compatible):

plugin.tx_tilemaps.settings.loadAssetsInTemplate = 1
Value Behaviour
0 (default) Assets loaded globally via page.includeCSS / page.includeJSFooter — identical to previous behaviour
1 Assets registered via f:asset.css / f:asset.script inside the plugin template, so they are only added to pages that render a map

Upgrade path

No action required for existing installations. To opt in, add to your site TypoScript:

plugin.tx_tilemaps.settings.loadAssetsInTemplate = 1

Notes

  • Both defer scripts are registered in order (jquery before tilemapsmapcreator), guaranteeing correct execution order.

How to test

  • With loadAssetsInTemplate = 0 (default): verify CSS and JS are present in the page source on all pages, including those without a map.
  • With loadAssetsInTemplate = 1: verify CSS and JS are absent on pages without a map and present (before </body>) on pages with a map.
  • Map functionality (markers, popups, tile loading) works correctly in both modes.
Adds a TypoScript constant that controls whether the extension's CSS and JavaScript assets are loaded globally on every page or only on pages that actually render a tile map. ### Motivation Previously, `MapCreator.css`, jQuery, and `MapCreator.js` were included on every page of the site via `page.includeCSS` / `page.includeJSFooter`, regardless of whether a map was present. This is unnecessary overhead on pages without a map. ### Changes **New constant** (default `0`, fully backward-compatible): ```typo3_typoscript plugin.tx_tilemaps.settings.loadAssetsInTemplate = 1 ``` | Value | Behaviour | |---|---| | `0` (default) | Assets loaded globally via `page.includeCSS` / `page.includeJSFooter` — identical to previous behaviour | | `1` | Assets registered via `f:asset.css` / `f:asset.script` inside the plugin template, so they are only added to pages that render a map | ### Upgrade path No action required for existing installations. To opt in, add to your site TypoScript: ```typo3_typoscript plugin.tx_tilemaps.settings.loadAssetsInTemplate = 1 ``` ### Notes - Both `defer` scripts are registered in order (`jquery` before `tilemapsmapcreator`), guaranteeing correct execution order. ### How to test - [ ] With `loadAssetsInTemplate = 0` (default): verify CSS and JS are present in the page source on all pages, including those without a map. - [ ] With `loadAssetsInTemplate = 1`: verify CSS and JS are absent on pages without a map and present (before `</body>`) on pages with a map. - [ ] Map functionality (markers, popups, tile loading) works correctly in both modes.
Add TypoScript constant plugin.tx_tilemaps.settings.loadAssetsInTemplate
(default: 0, backward-compatible).

When set to 1, the global page.includeCSS / page.includeJSFooter includes
for MapCreator.css, jQuery, and MapCreator.js are suppressed. Instead, the
Display template registers them via f:asset.css / f:asset.script (TYPO3
AssetCollector) only when the plugin is rendered on the current page.
This avoids loading Leaflet assets on pages that contain no map.
trokohl approved these changes 2026-05-15 20:58:08 +02:00
trokohl left a comment

looks good

looks good
Sign in to join this conversation.
No description provided.