Is it a good idea to serve different jQuery versions based on conditional comments?

StackOverflow https://stackoverflow.com/questions/16670111

  •  30-05-2022
  •  | 
  •  

Вопрос

With jQuery 2.0 being released, I wonder if there are problems likely to occurr when serving different versions of jQuery for IE8 and lower and other browsers with the use of "conditional comments":

<!DOCTYPE html>
    <head>
        <!--[if lte IE 8]>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <![endif]-->

        <!--[if gt IE 8]>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
        <![endif]-->

        <!--[if !IE]> -->
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
        <!-- <![endif]-->
    </head>
    <body>

    </body>
</html>

Since the release notes state, that

jQuery 2.0 has the same API as jQuery 1.9

I do assume that it would be save to take that approach even with an extensive amount of existing jQuery code. Am I missing something?

Это было полезно?

Решение

Opinion type question:

My Opinion

Most everything in 2.0 is the same with the HTML5 exception. Many "vanilla" JS functions have been replaced with jQuery style mark-up (this is just from my observance of the code) and the code is now making use of newly implemented "standards", thus making it incompatible for older IE.

However, at current, the name-spacings are the same. So the thought is, I would say it's not bad at all, but, just like with previous versions of jQuery, don't expect what looks one way in a HTML5 browser (Chrome, FF, IE9+) to look the same in an older browser. U may still want to do some checks for possible IE specifics as with previous versions. This is really nothing new.

More often than not, a blanketed jQuery mark-up will do fine, however you might notice slim difference. One for instance is how IE 7 handles .animate on certain styles as opposed to how IE 9 or 10 handles them. As I said before, this is really nothing new.

I personally design a sight to be ready with the latest in standards and then "back version" for compatibility with older browsers. I do this simply because, whatever I need to throw a "specific" in for, usually does not amount to much compared to the rest of the code. Also, by the time I finish development on something, one of the older ones I may have been expected to support, may no longer be an issue.

If it helps any, MS has already announced slow but steady drops of support for everything beneath Vist/IE9 over the next half decade or so. Expect to see less and less demand for older browser support. http://support.microsoft.com/gp/lifeadditionalproducts (there is a better article from them in Whitepapers, but it's in my email, not sure where their Whitepapers listing are online)

One other "gotchya" I've found lately, Firefox is becoming more like Microsoft. I've found they are very much trying to incorporate their "own standards" and pushing in an opposite direction from what "I" consider standard development. This has become more and more of an issue as I find things that "work in all browsers (even IE7!), BUT FIREFOX!" I haven't investigated enough to see why FF is changing so much, but they are definitely becoming the new "IE Headache" for development.

One prime example, CSS Style in header having any incompleteness or even certain CSS3 standards that the new FF engine doesn't like will KILL an entire page. Just off the top of my head, one issue I ran into (if i'm remembering this correctly, it was a few weeks ago) was something I was doing with table rows and :after. Firefox would get to that one line in my CSS and "BOOM! DOA!" No JS would work, no styling after that would work. I changed that one line to use a combo of nth-child and + and suddenly had no more argument out of FF.

I used to love FF, but with IE finally catching up, MS announcing drop in support for "bad old carp" and Mozilla switching gears to fall behind (again my opinion), I would look to -mozilla- as being the new "behind it all" browser you must make "conditional" statements for.


UPDATE [6/5/13]
Upon receiving new points on this post, I took a minute to review it and thought I would share one other "gotchya" I have found with jQuery Name-Spacing. I don't know why I didn't mention it before, other than it's kind of old and I suppose I assumed most people would know. However, due to other help I've given lately, I've found it to be quite "unknown".

One older "gotchya" with jQuery came with the release of 1.7. If you look it up, you'll see, they changed a MAJOR name-spacing, that later became completely deprecated. The name-spaces for $.bind, $.delegate, and $.live were replaced with easier to follow name-spaces of $.on and $.off. This of course was a bit of a pain for developers moving into the new as it required an if statement based on versions.

Again, this is an issue only for switching between jQuery versions of 1.7+newer and > 1.7!

IF you choose to flip between newer and older jQuery, then I suggest you wrap your delegated functions in a named method. They can then be called like $(document).on("event", "element", functionName). Don't forget the parameter of your named function will be event. Also, If you missed the solution to this and need it (the if statement), it's as simple as follows:

if ($.fn.on) {
    /*
     * is using jQuery ver >= 1.7
     * do work as necessary using:
     * $(document).on("event", "selector", callback)
    */
}
else {
    /*
     * is using jQuery ver < 1.7
     * do work as necessary using something like:
     * $(document).live("event", "selector", callback)
    */
}

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top