How cachebuster works
What is cachebusting? Simply said, its a dynamic GET parameter added to your .js or .css file so the browser is forced to refetch the resource when there is a known change.
The Assets class provides a few scenarios of cachebusting when enqueueing scripts and styles.
NPM Dependency
Adding a dependency to
package.json(usingyarn add)Copy to
plugins/your-plugin/src/public/lib/(usingyarn grunt libs:copy)Use
Assets#enqueueLibraryScript()to enqueue the handle
The cachebuster is applied with the package version of the dependency.
Entrypoints
Start developing on your entrypoints with
yarn docker:start``Change some code and webpack will transform the entrypoints automatically to production / development code
Use
Assets#enqueueScript()to enqueue the handle
The cachebuster is applied with a hash (hash comes from webpack).
Unknown resources
You want to use a JavaScript library which is not installable through yarn
Put the files manually to
plugins/your-plugin/src/public/lib``Use
Assets#enqueLibraryScript()(orwp_enqueue_scriptdirectly) to enqueue the handle
The cachebuster is applied with your plugins' version.
Last updated