Offer unminified assets for debugging
Be nice to other developers ;DDuring my study of WordPress plugins, I came across SearchWP Live Ajax Search. It contains short code that made me happy and I think every WordPress plugin should implement it. The code is very simple, but it does what I need. It offers plugin scripts in unminified version for debuging.
Of course, plugins should load minified versions of all assets, but if you want to debug them, it’s a pain 🙂 I can’t even count how many times I’ve tested a minified version of javascript, and this approach would make things immensely easier for me.
How to do this?
Just add this small check to you code and then use $debug
as suffix in script registration.
$debug = (defined( 'SCRIPT_DEBUG' ) && (true === SCRIPT_DEBUG)) ||
(isset( $_GET['script_debug'])) ? '' : '.min';
wp_register_script(
'custom-script', ASSETS_URL . "javascript/script{$debug}.js",
[ 'jquery' ],
ASSETS_VERSION,
true
);
If you define SCRIPT_DEBUG
or pass script_debug
as parameter in URL, it loads that script unminified.
What you think about this approach?