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.
- 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
{% hint style="success" %} The cachebuster is applied with the package version of the dependency. {% endhint %}
{% page-ref page="../typescript-development/add-external-library.md" %}
- 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
{% hint style="success" %} The cachebuster is applied with a hash (hash comes from webpack). {% endhint %}
{% page-ref page="../typescript-development/using-entrypoints.md" %}
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_script
directly) to enqueue the handle
{% hint style="success" %} The cachebuster is applied with your plugins' version. {% endhint %}