Posted on

Using dynamic version parameter in wp_enqueue_style to prevent caching assets

As browser caching mechanisms are becoming more and more aggressive, it could be very handy – when in development stage – to dynamically purge assets cache using the “version” argument when enqueuing scripts and styles in WordPress.

The following snippet is very simple and should be adapt to your workflow but demonstrates the basic of that “cache purging” tip. WordPress will add a different version of your stylesheet and or javascript file every time you made modification to it thanks to the php filemtime() builtin function.

Please note that once in “production” you should avoid this and use null as the version argument.

Leave a Reply

Your email address will not be published. Required fields are marked *