| @@ -77,8 +77,20 @@ | ||
| 77 | 77 | public static function get_register_scripts() { |
| 78 | 78 | $script_loading_strategy = \ABlocks\Helper::get_script_loading_strategy(); |
| 79 | 79 | $args = [ 'strategy' => $script_loading_strategy ]; |
| 80 | 80 | return apply_filters('ablocks/register_scripts', [ |
| 81 | + // Data-only handle (no src) that hosts the single frontend | |
| 82 | + // ABlocksGlobal payload. Every aBlocks frontend script depends on it | |
| 83 | + // — directly, or transitively through ablocks-common-script — so WP | |
| 84 | + // prints the object exactly once per page instead of once per block | |
| 85 | + // script handle (asset-generation off) or once per combined template | |
| 86 | + // script (asset-generation on). See Assets::localize_globals_once(). | |
| 87 | + 'ablocks-globals' => [ | |
| 88 | + 'url' => false, | |
| 89 | + 'deps' => array(), | |
| 90 | + 'ver' => ABLOCKS_VERSION, | |
| 91 | + 'args' => array(), | |
| 92 | + ], | |
| 81 | 93 | 'ablocks-prism-script' => [ |
| 82 | 94 | 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism.js', |
| 83 | 95 | 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism.js', |
| 84 | 96 | 'deps' => array(), |
| @@ -137,9 +149,13 @@ | ||
| 137 | 149 | ], |
| 138 | 150 | 'ablocks-common-script' => [ |
| 139 | 151 | 'path' => ABLOCKS_ASSETS_PATH . 'build/blocks-common.js', |
| 140 | 152 | 'url' => ABLOCKS_ASSETS_URL . 'build/blocks-common.js', |
| 141 | - 'deps' => array(), | |
| 153 | + // Every block script depends on this handle (see | |
| 154 | + // BlockBaseAbstract::get_script_depends), so hanging | |
| 155 | + // ablocks-globals off it makes the payload reachable from any | |
| 156 | + // rendered block without touching each block's own deps. | |
| 157 | + 'deps' => array( 'ablocks-globals' ), | |
| 142 | 158 | 'ver' => false, |
| 143 | 159 | 'args' => $args, |
| 144 | 160 | 'dependencies' => ABLOCKS_ASSETS_PATH . 'build/blocks-common.asset.php' |
| 145 | 161 | ], |