On 2010-01-22 21:31, Kia wrote:
I'm writing a userscript for Google. The script should work on ANY
page.

My current problem is to understand how to include jQuery into these
pages.

This is a little complex:

1. I have a vague memory of reading that some of the Google-pages have
theire own API for inluding libraries. Google might even be using
jQuery on some pages, using their own library. I want my script to be
as fast as possible - and it feels like a stupid idea to include
jQuery AGAIN, if it's already available. What do you think?

When including scripts, resources, and so forth into a userscript, download time is irrelevant: GM caches the included files on disk when the script is installed (and doesn't update them unless and until the script is updated). What's more, the two loaded libraries can't even interfere with each other, as GM runs userscripts in a special scripting context <http://wiki.greasespot.net/Category:Scripting_context> for security and other reasons. So don't worry about it at all (except to make sure your script updates itself <http://userscripts.org/guides/16> in ). Yes, in a nitpicky way, it "matters" that the same few hundred KiB is double-loaded in Firefox, but realistically, it's not a big deal, and micro-optimizing that is just going to slow you down too much. (And break your script a lot, too.)
2. If jQuery is not included on the page, then I would like to include
the Google hosted jQuery-js file.

Use something like this in the metadata block <http://wiki.greasespot.net/Metadata_block> of your userscript:

// @include       http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js

(location taken from http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery, linked by http://jquery.com/ download instructions)
Would it be possible (and HOW?) to only include the Google-hosted
jQuery when/if needed? And use the Google-API otherwise?

Not really, and per above, it's not necessary either -- or useful, IMHO.
/Kia

Hope this helps.

--
cc | pseudonymous |<http://carlclark.mp/>


--
? I hit the CTRL key but I'm still not in control! ? http://tagzilla.mozdev.org v0.066

--
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to greasemonkey-us...@googlegroups.com.
To unsubscribe from this group, send email to 
greasemonkey-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to