Use Google Libraries - Version 1.0.5

Version Description

Implimented a pair of suggestions from Peter Wilson.

  • It should detect when a page is loaded over https and load the libraries over https accordingly
  • It no longer drops the micro version number from the url. The reasons for this are twofold:
    • It ensures the version requested is the version received.
    • Google's servers set the expires header for 12 months for these urls, as opposed to 1 hour. This allows clients to cache the file for up to a year without needing to retrieve it again from Google's servers. If the version requested by your WordPress install changes, so will the URL so there's no worry that you'll keep loading an old version.

=

Download this release

Release Info

Developer jczorkmid
Plugin Icon wp plugin Use Google Libraries
Version 1.0.5
Comparing to
See all releases

Code changes from version 1.0 to 1.0.5

Files changed (2) hide show
  1. README.txt +24 -7
  2. use-google-libraries.php +34 -33
README.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Use Google Libraries ===
2
  Contributors: jczorkmid
3
  Donate link: http://jasonpenney.net/donate
4
- Tags: javascript, performance, CDN, Google, jQuery, Prototype, MooTools, Dojo
5
  Requires at least: 2.6
6
- Tested up to: 2.7b3
7
- Stable tag: 1.0
8
 
9
  Allows your site to use common javascript libraries from Google's AJAX
10
  Libraries CDN, rather than from Wordpress's own copies.
@@ -23,6 +23,10 @@ This provides numerous potential performance benefits:
23
  * uses compressed versions of the libraries (where available)
24
  * Google's servers are set up to negotiate HTTP compression with the requesting browser
25
 
 
 
 
 
26
  = Supported Libraries and Components =
27
 
28
  * [Dojo](http://dojotoolkit.org/)
@@ -46,10 +50,6 @@ Google has stated that they intend to keep every file they've hosted
46
  available indefinitely, so you shouldn't need to worry about them
47
  disappearing.
48
 
49
- This plugin loads scripts using only their major and minor versions, so if
50
- WordPress asks for jQuery 2.6.3, the plugin will load the latest 2.6.x
51
- available on Googles servers.
52
-
53
  == Technical Details ==
54
 
55
  **Use Google Libraries** uses the following hooks (each with a priority of 1000).
@@ -84,3 +84,20 @@ inspired by John Blackbourn's
84
  **[Google AJAX Libraries](http://lud.icro.us/wordpress-plugin-google-ajax-libraries/)**,
85
  which has very similar goals to this plugin.
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  === Use Google Libraries ===
2
  Contributors: jczorkmid
3
  Donate link: http://jasonpenney.net/donate
4
+ Tags: javascript, performance, CDN, Google, jQuery, Prototype, MooTools, Dojo, Google AJAX Libraries API
5
  Requires at least: 2.6
6
+ Tested up to: 2.7.1
7
+ Stable tag: 1.0.5
8
 
9
  Allows your site to use common javascript libraries from Google's AJAX
10
  Libraries CDN, rather than from Wordpress's own copies.
23
  * uses compressed versions of the libraries (where available)
24
  * Google's servers are set up to negotiate HTTP compression with the requesting browser
25
 
26
+ For a more detailed look see Dave Ward's [3 reasons why you should let
27
+ Google host jQuery for
28
+ you](http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/).
29
+ .
30
  = Supported Libraries and Components =
31
 
32
  * [Dojo](http://dojotoolkit.org/)
50
  available indefinitely, so you shouldn't need to worry about them
51
  disappearing.
52
 
 
 
 
 
53
  == Technical Details ==
54
 
55
  **Use Google Libraries** uses the following hooks (each with a priority of 1000).
84
  **[Google AJAX Libraries](http://lud.icro.us/wordpress-plugin-google-ajax-libraries/)**,
85
  which has very similar goals to this plugin.
86
 
87
+ == Changelog ==
88
+
89
+ = 1.0.5 =
90
+
91
+ Implimented a pair of
92
+ [suggestions](http://jasonpenney.net/wordpress-plugins/use-google-libraries/comment-page-1/#comment-32427)
93
+ from [Peter Wilson](http://peterwilson.cc/).
94
+
95
+ + It should detect when a page is loaded over https and load the libraries over https accordingly
96
+ + It no longer drops the micro version number from the url. The reasons for this are twofold:
97
+ + It ensures the version requested is the version received.
98
+ + Google's servers set the expires header for 12 months for these urls, as opposed to 1 hour. This allows clients to cache the file for up to a year without needing to retrieve it again from Google's servers. If the version requested by your WordPress install changes, so will the URL so there's no worry that you'll keep loading an old version.
99
+
100
+ == Future Plans ==
101
+
102
+ + add ability to enable/disable loading from Google for specific libraries
103
+ + add ability to request a newer version than your WordPress install registers by default
use-google-libraries.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /*
3
- Plugin Name: Use Google Libraries
4
- Plugin URI: http://jasonpenney.net/wordpress-plugins/usegooglelibraries/
5
- Description:Allows your site to use common javascript libraries from Google's AJAX Libraries CDN, rather than from Wordpress's own copies.
6
- Version: 1.0
7
- Author: Jason Penney
8
- Author URI: http://jasonpenney.net/
9
  */
10
 
11
  /* Copyright 2008 Jason Penney (email : jpenney@jczorkmid.net )
@@ -51,24 +51,24 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
51
  */
52
  function __construct(){
53
  $this->google_scripts = array(
54
- 'jquery' => array( 'jquery','jquery.min'),
55
- 'jquery-ui-core' => array('jqueryui','jquery-ui.min'),
56
- 'jquery-ui-tabs' => array('',''),
57
- 'jquery-ui-sortable' => array('',''),
58
- 'jquery-ui-draggable' => array('',''),
59
- 'jquery-ui-resizable' => array('',''),
60
- 'jquery-ui-dialog' => array('',''),
61
- 'prototype' => array('prototype','prototype'),
62
- 'scriptaculous-root' => array('scriptaculous', 'scriptaculous'),
63
- 'scriptaculous-builder' => array('',''),
64
- 'scriptaculous-effects' => array('',''),
65
- 'scriptaculous-dragdrop' => array('',''),
66
- 'scriptaculous-controls' => array('',''),
67
- 'scriptaculous-slider' => array('',''),
68
- 'scriptaculous-sound' => array('',''),
69
- 'mootools' => array('mootools','mootools-yui-compressed'),
70
- 'dojo' => array('dojo','dojo.xd')
71
- );
72
  add_action( 'wp_default_scripts', array(&$this,"replace_default_scripts"),1000);
73
  add_filter( 'print_scripts_array',array(&$this,"jquery_noconflict"),1000);
74
  add_filter( 'script_loader_src', array(&$this,"remove_ver_query"),1000);
@@ -89,18 +89,19 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
89
 
90
  // default to requested ver
91
  $ver = $script->ver;
92
- // drop the micro number
93
- if ( preg_match( '/[0-9]+\.[0-9]+/', $ver, $match ) ) {
94
- $ver = $match[0];
95
- }
96
-
97
-
98
- // if $lib is empty, then this script does not need to be
99
- // exlicitly loaded when using googleapis.com, but we need to keep
100
- // it around for dependencies
101
  if ($lib != '') {
102
  // build new URL
103
  $script->src = "http://ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
 
 
 
 
 
 
104
  } else {
105
  $script->src = "";
106
  }
1
  <?php
2
  /*
3
+ Plugin Name: Use Google Libraries
4
+ Plugin URI: http://jasonpenney.net/wordpress-plugins/use-google-libraries/
5
+ Description:Allows your site to use common javascript libraries from Google's AJAX Libraries CDN, rather than from Wordpress's own copies.
6
+ Version: 1.0.5
7
+ Author: Jason Penney
8
+ Author URI: http://jasonpenney.net/
9
  */
10
 
11
  /* Copyright 2008 Jason Penney (email : jpenney@jczorkmid.net )
51
  */
52
  function __construct(){
53
  $this->google_scripts = array(
54
+ 'jquery' => array( 'jquery','jquery.min'),
55
+ 'jquery-ui-core' => array('jqueryui','jquery-ui.min'),
56
+ 'jquery-ui-tabs' => array('',''),
57
+ 'jquery-ui-sortable' => array('',''),
58
+ 'jquery-ui-draggable' => array('',''),
59
+ 'jquery-ui-resizable' => array('',''),
60
+ 'jquery-ui-dialog' => array('',''),
61
+ 'prototype' => array('prototype','prototype'),
62
+ 'scriptaculous-root' => array('scriptaculous', 'scriptaculous'),
63
+ 'scriptaculous-builder' => array('',''),
64
+ 'scriptaculous-effects' => array('',''),
65
+ 'scriptaculous-dragdrop' => array('',''),
66
+ 'scriptaculous-controls' => array('',''),
67
+ 'scriptaculous-slider' => array('',''),
68
+ 'scriptaculous-sound' => array('',''),
69
+ 'mootools' => array('mootools','mootools-yui-compressed'),
70
+ 'dojo' => array('dojo','dojo.xd')
71
+ );
72
  add_action( 'wp_default_scripts', array(&$this,"replace_default_scripts"),1000);
73
  add_filter( 'print_scripts_array',array(&$this,"jquery_noconflict"),1000);
74
  add_filter( 'script_loader_src', array(&$this,"remove_ver_query"),1000);
89
 
90
  // default to requested ver
91
  $ver = $script->ver;
92
+
93
+ // if $lib is empty, then this script does not need to be
94
+ // exlicitly loaded when using googleapis.com, but we need to keep
95
+ // it around for dependencies
 
 
 
 
 
96
  if ($lib != '') {
97
  // build new URL
98
  $script->src = "http://ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
99
+ // test for SSL
100
+ // thanks to suggestion from Peter Wilson (http://peterwilson.cc/)
101
+ if ((isset($_SERVER['HTTPS'])) AND ($_SERVER['HTTPS'] != ”) AND ($_SERVER['HTTPS'] != ‘off’)) {
102
+ //use ssl
103
+ $script->src = preg_replace('/^http:/', 'https:', $script->src);
104
+ }
105
  } else {
106
  $script->src = "";
107
  }