From f13a402572dbdb087ea2d6e84be1cc5727250ccd Mon Sep 17 00:00:00 2001 From: Hal Date: Sun, 3 Nov 2013 10:21:54 -0500 Subject: [PATCH 1/9] Adding configuration for deferring javascript. Also, a constant for disabling BWP, BWP_DISABLED. --- bwp-minify.php | 11 +++++++---- includes/class-bwp-minify.php | 20 +++++++++++++------- readme.txt | 12 +++++++++--- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/bwp-minify.php b/bwp-minify.php index 695d1ed..d36ee95 100644 --- a/bwp-minify.php +++ b/bwp-minify.php @@ -15,9 +15,12 @@ if (class_exists('BWP_MINIFY')) return; -// Frontend -require_once('includes/class-bwp-minify.php'); -$bwp_minify = new BWP_MINIFY(); +// DBS HB 2013-11-02 +if ( ! defined( 'BWP_DISABLED' ) || BWP_DISABLED == 'false' || BWP_DISABLED === false ) { + // Frontend + require_once('includes/class-bwp-minify.php'); + $bwp_minify = new BWP_MINIFY(); +} // Backend add_action('admin_menu', 'bwp_minify_init_admin', 1); @@ -26,4 +29,4 @@ function bwp_minify_init_admin() { global $bwp_minify; $bwp_minify->init_admin(); -} \ No newline at end of file +} diff --git a/includes/class-bwp-minify.php b/includes/class-bwp-minify.php index e997ecb..c47205d 100644 --- a/includes/class-bwp-minify.php +++ b/includes/class-bwp-minify.php @@ -98,6 +98,7 @@ function __construct($version = '1.2.3') 'enable_min_js' => 'yes', 'enable_min_css' => 'yes', 'enable_bloginfo' => 'yes', + 'defer_js' => 'no', 'select_buster_type' => 'none', 'select_time_type' => 60 ); @@ -110,6 +111,7 @@ function __construct($version = '1.2.3') add_action('init', array($this, 'default_minurl')); add_action('init', array($this, 'init')); + } function default_minurl() @@ -240,13 +242,14 @@ function build_option_pages() if ($page == BWP_MINIFY_OPTION_GENERAL) { $form = array( - 'items' => array('heading', 'checkbox', 'checkbox', 'checkbox', 'heading', 'input', 'input', 'input', 'select', 'heading', 'textarea', 'textarea', 'textarea', 'textarea'), + 'items' => array('heading', 'checkbox', 'checkbox', 'checkbox', 'checkbox', 'heading', 'input', 'input', 'input', 'select', 'heading', 'textarea', 'textarea', 'textarea', 'textarea'), 'item_labels' => array ( __('General Options', 'bwp-minify'), __('Minify JS files automatically?', 'bwp-minify'), __('Minify CSS files automatically?', 'bwp-minify'), __('Minify bloginfo() stylesheets?', 'bwp-minify'), + __('Defer JavaScript', 'bwp-minify'), __('Minifying Options', 'bwp-minify'), __('Minify URL (double-click to edit)', 'bwp-minify'), __('Cache directory (double-click to edit)', 'bwp-minify'), @@ -258,7 +261,7 @@ function build_option_pages() __('Scripts to be minified and then printed separately', 'bwp-minify'), __('Scripts to be ignored (not minified)', 'bwp-minify') ), - 'item_names' => array('h1', 'cb1', 'cb3', 'cb2', 'h2', 'input_minurl', 'input_cache_dir', 'input_maxfiles', 'select_buster_type', 'h3', 'input_header', 'input_footer', 'input_direct', 'input_ignore'), + 'item_names' => array('h1', 'cb1', 'cb3', 'cb2', 'cb4', 'h2', 'input_minurl', 'input_cache_dir', 'input_maxfiles', 'select_buster_type', 'h3', 'input_header', 'input_footer', 'input_direct', 'input_ignore'), 'heading' => array( 'h1' => '', 'h2' => __('Options that affect both your stylesheets and scripts.', 'bwp-minify'), @@ -282,7 +285,8 @@ function build_option_pages() 'checkbox' => array( 'cb1' => array(__('you can still use bwp_minify() helper function if you disable this.', 'bwp-minify') => 'enable_min_js'), 'cb3' => array(__('you can still use bwp_minify() helper function if you disable this.', 'bwp-minify') => 'enable_min_css'), - 'cb2' => array(__('most themes (e.g. Twenty Ten) use bloginfo() to print the main stylesheet (i.e. style.css) and BWP Minify will not be able to add it to the main minify string. If you want to minify style.css with the rest of your css files, you must enqueue it.', 'bwp-minify') => 'enable_bloginfo') + 'cb2' => array(__('most themes (e.g. Twenty Ten) use bloginfo() to print the main stylesheet (i.e. style.css) and BWP Minify will not be able to add it to the main minify string. If you want to minify style.css with the rest of your css files, you must enqueue it.', 'bwp-minify') => 'enable_bloginfo'), + 'cb4' => array(__('Deferring JavaScript can improve browser rendering speed.', 'bwp-minify') => 'defer_js') ), 'input' => array( 'input_minurl' => array('size' => 55, 'disabled' => ' readonly="readonly"', 'label' => sprintf(__('This should be set automatically. If you think the URL is too long, please read here to know how to properly modify this.', 'bwp-minify'), $this->plugin_url)), @@ -311,8 +315,8 @@ function build_option_pages() ); // Get the default options - $options = $bwp_option_page->get_options(array('input_minurl', 'input_cache_dir', 'input_maxfiles', 'input_header', 'input_footer', 'input_direct', 'input_ignore', 'input_custom_buster', 'select_buster_type', 'enable_min_js', 'enable_min_css', 'enable_bloginfo'), $this->options); - + $options = $bwp_option_page->get_options(array('input_minurl', 'input_cache_dir', 'input_maxfiles', 'input_header', 'input_footer', 'input_direct', 'input_ignore', 'input_custom_buster', 'select_buster_type', 'enable_min_js', 'enable_min_css', 'enable_bloginfo', 'defer_js'), $this->options); + // Get option from the database $options = $bwp_option_page->get_db_options($page, $options); @@ -749,7 +753,9 @@ function get_minify_tag($string, $type, $media = '') switch ($type) { case 'script': - $return = "\n"; + // DBS 2013-11-03 + $defer = ( 'yes' === $this->options[ 'defer_js' ] ) ? $defer = 'defer="defer" ' : ''; + $return = "\n"; break; case 'style': @@ -1190,4 +1196,4 @@ function print_footer_scripts_l10n() $this->print_scripts_l10n($this->footer_l10n); } } -?> \ No newline at end of file +?> diff --git a/readme.txt b/readme.txt index e0ff92d..218ae7a 100644 --- a/readme.txt +++ b/readme.txt @@ -1,15 +1,17 @@ === Better WordPress Minify === -Contributors: OddOneOut +Contributors: OddOneOut, dbswebsite Donate link: http://betterwp.net/wordpress-plugins/bwp-minify/ Tags: CSS, javascript, JS, minify, minification, optimization, optimize Requires at least: 2.8 Tested up to: 3.7 -Stable tag: 1.2.3 +Stable tag: 1.2.3-1 Allows you to minify your CSS and JS files for faster page loading for visitors. == Description == +This fork adds the ability to defer JavaScript. + **BWP MINIFY IS WORDPRESS 3.7 COMPATIBLE** Allows you to minify your CSS and JS files for faster page loading for visitors. This plugin uses the PHP library [Minify](http://code.google.com/p/minify/) and relies on WordPress's enqueueing system rather than the output buffer (will not break your website in most cases). This plugin is very customizable and easy to use. @@ -74,6 +76,10 @@ Please [help translate](http://betterwp.net/wordpress-tips/create-pot-file-using == Changelog == += 1.2.3-1 = +* Add a configuration option for deferring JavaScript +* Create a constant that allows programatically disabling BWP, ie BWP_DISABLED. + = 1.2.3 = * BWP Minify is now WordPress 3.7 compatible (compatibility issues with WordPress 3.5 and 3.6 have been fixed). * Updated Minify library to version 2.1.7 (security fix). This updated version of Minify also comes with an updated version of CSSMin library, which solves relative path issues in some plugins' CSS files (such as TablePress). @@ -183,4 +189,4 @@ Please [help translate](http://betterwp.net/wordpress-tips/create-pot-file-using == Upgrade Notice == = 1.0.0 = -* Enjoy the plugin! \ No newline at end of file +* Enjoy the plugin! From 3cb6039f46386d3109cf0dd5740fdbb3d9dd2e52 Mon Sep 17 00:00:00 2001 From: Hal Date: Sun, 3 Nov 2013 10:37:47 -0500 Subject: [PATCH 2/9] changing version strings --- bwp-minify.php | 2 +- includes/class-bwp-minify.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bwp-minify.php b/bwp-minify.php index d36ee95..130cc9d 100644 --- a/bwp-minify.php +++ b/bwp-minify.php @@ -3,7 +3,7 @@ Plugin Name: Better WordPress Minify Plugin URI: http://betterwp.net/wordpress-plugins/bwp-minify/ Description: Allows you to minify your CSS and JS files for faster page loading for visitors. This plugin uses the PHP library Minify and relies on WordPress's enqueueing system rather than the output buffer (will not break your website in most cases). This plugin is very customizable and easy to use. -Version: 1.2.3 +Version: 1.2.3-1 Text Domain: bwp-minify Domain Path: /languages/ Author: Khang Minh diff --git a/includes/class-bwp-minify.php b/includes/class-bwp-minify.php index c47205d..40b6d4b 100644 --- a/includes/class-bwp-minify.php +++ b/includes/class-bwp-minify.php @@ -73,7 +73,7 @@ class BWP_MINIFY extends BWP_FRAMEWORK { /** * Constructor */ - function __construct($version = '1.2.3') + function __construct($version = '1.2.3-1') { // Plugin's title $this->plugin_title = 'BetterWP Minify'; @@ -111,7 +111,6 @@ function __construct($version = '1.2.3') add_action('init', array($this, 'default_minurl')); add_action('init', array($this, 'init')); - } function default_minurl() From 8edfbd6e6f636b88bedec27785b4b66922ea25f4 Mon Sep 17 00:00:00 2001 From: Hal Date: Wed, 13 Nov 2013 10:38:58 -0500 Subject: [PATCH 3/9] bad comparison operator --- bwp-minify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bwp-minify.php b/bwp-minify.php index 130cc9d..0adda11 100644 --- a/bwp-minify.php +++ b/bwp-minify.php @@ -16,7 +16,7 @@ return; // DBS HB 2013-11-02 -if ( ! defined( 'BWP_DISABLED' ) || BWP_DISABLED == 'false' || BWP_DISABLED === false ) { +if ( ! defined( 'BWP_DISABLED' ) || BWP_DISABLED === 'false' || BWP_DISABLED === false ) { // Frontend require_once('includes/class-bwp-minify.php'); $bwp_minify = new BWP_MINIFY(); From 3f62e0e48c6f96611594d1ee4b289014c9a4fbcc Mon Sep 17 00:00:00 2001 From: Hal Date: Wed, 13 Nov 2013 12:37:39 -0500 Subject: [PATCH 4/9] silence strange / bogus warnings FIXME --- min/lib/Minify/Cache/File.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/min/lib/Minify/Cache/File.php b/min/lib/Minify/Cache/File.php index 27b424a..b31d7ef 100644 --- a/min/lib/Minify/Cache/File.php +++ b/min/lib/Minify/Cache/File.php @@ -97,7 +97,11 @@ public function display($id) public function fetch($id) { if ($this->_locking) { - $fp = fopen($this->_path . '/' . $id, 'rb'); + // fixme: this occasionally spits out bogus "no such file" warnings and cannot modify header noise. 2013-11-13 HB + @$fp = fopen($this->_path . '/' . $id, 'rb'); + if ( false === $fp ) { + return; + } flock($fp, LOCK_SH); $ret = stream_get_contents($fp); flock($fp, LOCK_UN); From 4343ccbf2a2828cc24fc898e02267b020431d982 Mon Sep 17 00:00:00 2001 From: Hal Date: Mon, 18 Nov 2013 11:58:37 -0500 Subject: [PATCH 5/9] The disable CONSTANT broke admin layer. --- bwp-minify.php | 2 +- min/lib/Minify/Cache/File.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bwp-minify.php b/bwp-minify.php index 0adda11..8133a96 100644 --- a/bwp-minify.php +++ b/bwp-minify.php @@ -16,7 +16,7 @@ return; // DBS HB 2013-11-02 -if ( ! defined( 'BWP_DISABLED' ) || BWP_DISABLED === 'false' || BWP_DISABLED === false ) { +if ( ! defined( 'BWP_DISABLED' ) || BWP_DISABLED === 'false' || BWP_DISABLED === false || is_admin() ) { // Frontend require_once('includes/class-bwp-minify.php'); $bwp_minify = new BWP_MINIFY(); diff --git a/min/lib/Minify/Cache/File.php b/min/lib/Minify/Cache/File.php index b31d7ef..bed32cb 100644 --- a/min/lib/Minify/Cache/File.php +++ b/min/lib/Minify/Cache/File.php @@ -97,7 +97,7 @@ public function display($id) public function fetch($id) { if ($this->_locking) { - // fixme: this occasionally spits out bogus "no such file" warnings and cannot modify header noise. 2013-11-13 HB + // FIXME: this occasionally spits out bogus "no such file" warnings and cannot modify header noise. Possibly due to symlinks. 2013-11-13 HB @$fp = fopen($this->_path . '/' . $id, 'rb'); if ( false === $fp ) { return; From 8e5017d7f2084288ab907665e1611e43a9027ea7 Mon Sep 17 00:00:00 2001 From: Hal Date: Mon, 25 Nov 2013 22:16:34 -0500 Subject: [PATCH 6/9] Handle protocol-less schemes per cameronr --- includes/class-bwp-minify.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/class-bwp-minify.php b/includes/class-bwp-minify.php index 40b6d4b..fc0311d 100644 --- a/includes/class-bwp-minify.php +++ b/includes/class-bwp-minify.php @@ -560,6 +560,11 @@ function is_local($src = '') if (false === strpos($src, '://') && substr($src, 0, 1) != '/') { $src = 'http://'. $src; } + // DBS 2013-11-25, handle protocol-less scheme + if (strncmp($src, '//', 2) == 0) { + $protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https:' : 'http:'; + $src = $protocol . $src; + } $url = @parse_url($src); $blog_url = @parse_url(home_url()); if (false === $url) From 6567cd2fcae28be0219cb9b330fb8dd639de3bb8 Mon Sep 17 00:00:00 2001 From: Hal Burgiss Date: Tue, 26 Nov 2013 09:54:30 -0500 Subject: [PATCH 7/9] Setting bubbleCssImports to true as default, due to @import issues. Isn't this more sane anyway? --- min/config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/min/config.php b/min/config.php index 33829a1..69c933b 100644 --- a/min/config.php +++ b/min/config.php @@ -91,7 +91,8 @@ * move all @imports to the top of the output. Note that moving @imports could * affect CSS values (which is why this option is disabled by default). */ -$min_serveOptions['bubbleCssImports'] = false; + // DBS 2013-11-26, set to true ... why not? +$min_serveOptions['bubbleCssImports'] = true; /** From 1d81d4da0d326f500fcc9bce44c2840ddcfa2a66 Mon Sep 17 00:00:00 2001 From: Hal Date: Thu, 12 Dec 2013 21:23:37 -0500 Subject: [PATCH 8/9] tweak --- min/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/config.php b/min/config.php index 69c933b..20a5632 100644 --- a/min/config.php +++ b/min/config.php @@ -104,7 +104,7 @@ * Note: Despite this setting, if you include a number at the end of the * querystring, maxAge will be set to one year. E.g. /min/f=hello.css&123456 */ -$min_serveOptions['maxAge'] = 7200; +$min_serveOptions['maxAge'] = 86400; /** From 060eed4130f2db18f29e22b081ab2022fe1b41e6 Mon Sep 17 00:00:00 2001 From: Hal Date: Sun, 15 Dec 2013 18:04:53 -0500 Subject: [PATCH 9/9] increase max-cache lifetime to 10 days --- min/config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/min/config.php b/min/config.php index 20a5632..a728588 100644 --- a/min/config.php +++ b/min/config.php @@ -104,7 +104,8 @@ * Note: Despite this setting, if you include a number at the end of the * querystring, maxAge will be set to one year. E.g. /min/f=hello.css&123456 */ -$min_serveOptions['maxAge'] = 86400; +// DBS 2013-12-15, increase max age for better caching +$min_serveOptions['maxAge'] = 86400*10; /**