Thanks for your advice, we adjusted some things in our plugin:
http://plugins.trac.wordpress.org/changeset/388776/pronamic-google-maps
On archive pages, and other special pages, the script will still always load. It’s not easy to tell if the script is not needed on these pages. Do you have an idea how to optimze this further?
if(is_singular()) {
if(pronamic_google_maps_is_active()) {
wp_enqueue_script('pronamic-google-maps-site');
}
} else {
wp_enqueue_script('pronamic-google-maps-site');
}
Okey.
Maybe you could give admins the opportunity to choose wich pages the script should load on? For me it would be enough to show it on single pages of a custom post type and on one page.
Couldn’t it be part of the map rendering?
I don’t think that is possible, scripts have to be enqueued before wp_head() is executed.
http://codex.wordpress.org/Function_Reference/wp_register_script
Thanks for the link, I made some adjustments and this could work. However the Google Maps API documentation says that the scripts should be place in the <head> section.
http://code.google.com/intl/nl/apis/maps/documentation/javascript/tutorial.html#Loading_the_Maps_API
With the solution from Scribu the scripts are placed in the footer (before the </body> tag). Do you have any idea what kind of effect this will have?
The solution is working in Firefox 3.6.16, Internet Explorer 9 and Google Chrome…
Some more related links:
– http://beerpla.net/2010/01/15/follow-up-to-loading-css-and-js-conditionally/
– http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/
I guess Google just assumes that a map should load as early as possible. But as far as I know it works just fine if you include the scripts at the end of your markup.
Ok, thanks. We used the solution from Scribu in version 1.8:
http://wordpress.org/extend/plugins/pronamic-google-maps/
I am running wp_enqueue_script(‘pronamic-google-maps-site’); in functions-user.php when the page loads but the script is not being inserted into the HTML code.
Other scripts are being properly enqueued from the same code block – do I need to add something else?
Do you enqueue the script within the ‘wp_enqueue_scripts’ routine?
function prefix_enqueue_scripts() {
wp_enqueue_script('pronamic-google-maps-site');
}
add_action('wp_enqueue_scripts', 'prefix_enqueue_scripts');
http://codex.wordpress.org/Function_Reference/wp_enqueue_script