in Web Development, WordPress

SCRIPT_DEBUG constant in WordPress

By default WordPress loads minified version of CSS and JS files so that it would contribute in loading time. As from the user point it is helpful but as for the developer point it might be sometime painful during development. Minified CSS and JS files are very hard to read and understand, so debugging becomes complicated in that case.

In such cases it would be very easy if we could see the unminifed versions of CSS and JS, isn’t it?
Yes, it would be very easy and WordPress have solutions for it.

It is SCRIPT_DEBUG constant.

Just put following line as you define constant WP_DEBUG in wp-config.php file.

define( 'SCRIPT_DEBUG', true );

After you put this line in wp-config.php and view page source then you can see the unminified version of the CSS and JS.

That’s a great start, but what about its use in plugin or theme?
Definitely there SCRIPT_DEBUG has its use in plugin or theme. Its better to have minified and unminifed version of CSS and JS in our plugin or theme. We can load our minified version of files using following method.

And this would load minified version of you files if SCRIPT_DEBUG is not defined or false.

Hope this small article would be some how helpful to you. Let me know your feedback.