patric-boehner
11/13/2015 - 6:09 AM

Wordpress cache busting while in local development with debug on.

Wordpress cache busting while in local development with debug on.

<?php

//* Local development cache busting if debug is on
//* Otherwsie return static number
define ('VERSION', '1.1');

function version_id() {
	if ( WP_DEBUG )
	return time();
	return VERSION;
}

//* Load Login Style
function pb_login_styles() {
	wp_enqueue_style( 'login_styles', get_stylesheet_directory_uri() . '/lib/css/login.css', false, version_id() );
}

//* Scroll Back To The Top
function pb_scroll_top_script_enqueue() {
    wp_enqueue_script( 'scroll-to-top', get_stylesheet_directory_uri() . '/js/scroll-to-top.js', array( 'jquery' ), version_id(), true );
}

Cache Busting While Debug Is On

A quick way to bust cache of scripts and style sheets in wordpress when debug is on (something you would most likely only be doing when in local development). Sets a new version number every time the page is releated based on the current Unix timestamp, otherwise return a set static number you can manualy update.

Example result in DEBUG mode:

<script type="text/javascript" src="http://localhost/wordpress.../js/scroll-to-top.js?ver=1447394696"></script>

Example result with DEBUG off:

<script type="text/javascript" src="http://localhost/wordpress.../js/scroll-to-top.js?ver=1.1"></script>

Source: