Util to see if we should load a given chunk on a page. Just add data-load-chunk-UNIQUE to load that particular one on any element on the page.
Parameters:
Name | Type | Description |
---|---|---|
name | string | The chunk name. |
- Since
- 1.0.0
- Source
Returns:
Whether or not we should load the chunk.
- Type:
- boolean
Example
import { shouldLoadChunk } from "@gravityforms/utils";
// assuming there is a dom node present that has the data attribute: data-load-chunk-example
function Example() {
if ( shouldLoadChunk( 'example' ) ) {
import( '../example-module' \/* webpackChunkName:"scripts-admin.example" *\/ ).then(
( module ) => {
module.default();
}
);
}
}