Conquer Club

Greasemonkey-scripts and jQuery

Discuss developing tools and get details on Conquer Club's API.

Moderator: Tech Team

Forum rules
Please read the Community Guidelines before posting.

Greasemonkey-scripts and jQuery

Postby sherkaner on Sun Dec 19, 2010 8:00 am

I enjoy the jQuery-library when I write javascript, so I've added that to BOB. But it slowly became harder to do. So I guess I should share that knowledge.

At first, I just loaded it by adding a <script>-tag to the page with jQuery, and wait till it came available. In the end, this doesn't work because it could take .1 or .2 seconds extra to load. It wasn't really noticable at the start, and it was 1 time per page, but still it's better to fetch it directly.

Then I found out about @Require, which loads the file along with the script when installing, and so it doesn't cost any extra time. So I was satisfied with the result (except that 1 person complained about fetching things from google, the script is hosted there etc.).

After that, 2 problems came up: jQuery 1.4 came out, which did not work fully in greasemonkey, and I tried to make the script work in Chrome, which does not support @Require.
The solution for the latter was to include the jQuery-code in the script itself. It's ugly, but happily it's not too large after minification (script is still smaller now than when I started), and it doesn't complicate anything after that.
The other was to adapt the jQuery code in a specific place.. I chose not to get stuck with an old version, so I get the code, make the modifications and minify it through google closure. With jQuery 1.4.4, there seem to be 3 places the code has to be adjusted now, and I'm wondering if the speedup that came with 1.4 and 1.4.2 is worth making the changes.. In time, I hope a better solution will show up.
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: Greasemonkey-scripts and jQuery

Postby Dako on Mon Dec 20, 2010 4:57 am

I think you can include LABjs code into the script and load jQuery that way. After it has loaded - just call your BOB init function.

Here is the example code
Code: Select all
$LAB
   .script("jquery-1.4.4.min.js")
   .wait(function(){
      BOB.init();
   });


That will do the trick - I am most sure.
Image
User avatar
Colonel Dako
 
Posts: 3987
Joined: Sun Aug 26, 2007 9:07 am
Location: St. Petersburg, Russia

Re: Greasemonkey-scripts and jQuery

Postby sherkaner on Mon Dec 20, 2010 10:40 am

Yeah, I could do that. But I think the solution is pretty equal to my first variant. The downside (you have to wait till the thing is downloaded) is still true.
And the other disadvantage: If it adds it to the page (which is likely), Chrome won't have access to it.
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: Greasemonkey-scripts and jQuery

Postby Dako on Mon Dec 20, 2010 11:16 am

It is better to add jQuery externally because it may be already cached by client and will result in a small speed up. Loading it inline with the BOB script just slows every bob-load.

LBjs should work at Chrome afaik but I never tried it there.
Image
User avatar
Colonel Dako
 
Posts: 3987
Joined: Sun Aug 26, 2007 9:07 am
Location: St. Petersburg, Russia

Re: Greasemonkey-scripts and jQuery

Postby sherkaner on Mon Dec 20, 2010 3:27 pm

Dako wrote:It is better to add jQuery externally because it may be already cached by client and will result in a small speed up. Loading it inline with the BOB script just slows every bob-load.

LBjs should work at Chrome afaik but I never tried it there.

I did try require.js once (work-related), but I still think it adds things to the page (http://requirejs.org/docs/why.html , just checked labjs and it does about the same).

And the case I have here is different. Because the script is already at the client, it takes no time to fetch it, execution time is all that matters. Hitting the cache would result in a small speedup compared to fetching it from a server. But still it should be slower than actually having it in the script already.

LABjs should work in chrome, but not in chrome extensions I think. Extensions normally allow you to add extra files anyway, so it will be hard to get information on that. Time to try something out I guess.
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: Greasemonkey-scripts and jQuery

Postby ricaluanna on Tue Jul 05, 2011 8:35 pm

What is greasemonkey?
New Recruit ricaluanna
 
Posts: 1
Joined: Tue Jul 05, 2011 8:27 pm

Re: Greasemonkey-scripts and jQuery

Postby sherkaner on Wed Jul 06, 2011 3:33 pm

Firefox-addon

'Customize the way a web page displays or behaves, by using small bits of JavaScript.'
Well, the scripts here aren't that small any more..
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle


Return to Tools Development

Who is online

Users browsing this forum: No registered users