There are different JavaScript libraries such as jQuery,mootools,ajax etc available which helps us to add functionalities to our web applications.
Hundreds of plugins built using those libraries are making our tasks easy. So without actually peeping into the code we use those plugins.
Now, the problem arises when these libraries are used together.
I stuck in the same problem when I was implementing jquery in my application which already had lighbox implemented in it.
After researching a lot I figured out that prototype.js which was used for implementing Lightbox and jQuery.js in my application were conflicting.
The real problem was both libraries were using '$' as their main function name. Hence one library was breaking the behaviour of other library.
for e.g. in jquery we use :
$(function(){
---
---
});
Here '$' represents jQuery. Similarly in prototype.js for lightbox '$' was used which was representing its main function.
jQuery has provided us the solution to get rid of this problem. Simply use noConflict() function immediately after jQuery.js.
When you use noConflict(), jQuery will return $() to its previous owner and you will need to use jQuery() instead of shorthand $() function.
so it can be written as
jQuery(function(){
---
---
});
else...
var j=jQuery.noConflict();
so,
j(Function(){
--
--
});
So now, jQuery is compatible with other javascript libraries and can be used easily.
Saturday, November 7, 2009
Saturday, August 29, 2009
CSS SPRITE
What it is??
Technique wherein small images are consolidated at one place and then that consolidated image is used to apply those small images around your application.
Whole magic is done by background position property. By using background position property the exact position of the required image can be identified.
Why to use??
The technique helps you to reduce HTTP request and thus performance gaining of your application.
When you look for optimization of web application you look around to reduce the number of HTTP requests.
So here if you have 10 different small images in your application then 10 different HTTP requests would be sent to fetch those images from server. Wherein when we use CSS SPRITE, all 10 images are consolidated in one image and then only one HTTP request is sent to fetch the images.
Where it has been used??
CSS sprite is now majorly used. Put your firebug (in Firefox) on and see the CSS of yahoo.com, aol.com, digg.com all are using CSS sprite to display small images.
When to use??
Typically the technique should be used to access small images.
How to make it?
Sprite images can be build in photshop or to make your life easier there are number of CSS SPRITE generators available on web wherein they ask you to upload your images and build sprite image for you with respective background position of particular image. I use www.csssprites.com
Useful Resources:
Subscribe to:
Posts (Atom)