Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions bwp-minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="http://code.google.com/p/minify/">Minify</a> 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
Expand All @@ -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 || is_admin() ) {
// Frontend
require_once('includes/class-bwp-minify.php');
$bwp_minify = new BWP_MINIFY();
}

// Backend
add_action('admin_menu', 'bwp_minify_init_admin', 1);
Expand All @@ -26,4 +29,4 @@ function bwp_minify_init_admin()
{
global $bwp_minify;
$bwp_minify->init_admin();
}
}
26 changes: 18 additions & 8 deletions includes/class-bwp-minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
);
Expand Down Expand Up @@ -240,13 +241,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 <code>bloginfo()</code> 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'),
Expand All @@ -258,7 +260,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' => __('<em>Options that affect both your stylesheets and scripts.</em>', 'bwp-minify'),
Expand All @@ -282,7 +284,8 @@ function build_option_pages()
'checkbox' => array(
'cb1' => array(__('you can still use <code>bwp_minify()</code> helper function if you disable this.', 'bwp-minify') => 'enable_min_js'),
'cb3' => array(__('you can still use <code>bwp_minify()</code> helper function if you disable this.', 'bwp-minify') => 'enable_min_css'),
'cb2' => array(__('most themes (e.g. Twenty Ten) use <code>bloginfo()</code> to print the main stylesheet (i.e. <code>style.css</code>) and BWP Minify will not be able to add it to the main minify string. If you want to minify <code>style.css</code> with the rest of your css files, you must enqueue it.', 'bwp-minify') => 'enable_bloginfo')
'cb2' => array(__('most themes (e.g. Twenty Ten) use <code>bloginfo()</code> to print the main stylesheet (i.e. <code>style.css</code>) and BWP Minify will not be able to add it to the main minify string. If you want to minify <code>style.css</code> 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 <a href="%s#customization">here</a> to know how to properly modify this.', 'bwp-minify'), $this->plugin_url)),
Expand Down Expand Up @@ -311,8 +314,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);

Expand Down Expand Up @@ -557,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)
Expand Down Expand Up @@ -749,7 +757,9 @@ function get_minify_tag($string, $type, $media = '')
switch ($type)
{
case 'script':
$return = "<script type='text/javascript' src='" . $this->get_minify_src($string) . "'></script>\n";
// DBS 2013-11-03
$defer = ( 'yes' === $this->options[ 'defer_js' ] ) ? $defer = 'defer="defer" ' : '';
$return = "<script " . $defer . "type='text/javascript' src='" . $this->get_minify_src($string) . "'></script>\n";
break;

case 'style':
Expand Down Expand Up @@ -1190,4 +1200,4 @@ function print_footer_scripts_l10n()
$this->print_scripts_l10n($this->footer_l10n);
}
}
?>
?>
6 changes: 4 additions & 2 deletions min/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -103,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'] = 7200;
// DBS 2013-12-15, increase max age for better caching
$min_serveOptions['maxAge'] = 86400*10;


/**
Expand Down
6 changes: 5 additions & 1 deletion min/lib/Minify/Cache/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. Possibly due to symlinks. 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);
Expand Down
12 changes: 9 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -183,4 +189,4 @@ Please [help translate](http://betterwp.net/wordpress-tips/create-pot-file-using
== Upgrade Notice ==

= 1.0.0 =
* Enjoy the plugin!
* Enjoy the plugin!