Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Conflict with other AJAX libraries

    I have a big shiny button for launching my SmartClient app. My idea was that by showing this button on all my screens, the fancy new app would never be more than a click away for my users. This means that I need to load all the related javascript on every page (do the files get cached?). The latest problem I'm having is that SmartClient is sort of stomping over other JavaScript business I have going on my other pages. The main trouble is centered around some custom widgets I wrote that use the JQuery AJAX library. When I try to include the SmartClient AJAX files (particularly ISC_core.js) on the same page as one that needs JQuery, the JQuery stuff doesn't work (and generates lots of errors in FireFox's or Chrome's Javascript consoles).

    So, before I worry about trying to make different JavaScript libraries play nice together, maybe I should be asking if it's really feasible in terms of performance to be including all those SmartClient libraries (and my own app-related .js file--comparable in size and complexity to your showcase app) on every page. I've profiled the page loads using a timer in PHP, and the execution time seems no different, but there is definitely an additional noticeable lag when actually physically navigating pages.

    If that's a problem that can be surmounted or worked-around, then how do I go about scoping SmartClient to only be concerned with elements that were created with SmartClient, and not pollute other code?

    #2
    To avoid conflicts with JQuery, put SmartClient in strict namespace mode - see this discussion.

    Yes, the files are cached after the first time they are loaded.

    The best way to unobtrusively have an application launch like yours without impacting the interactivity of the website is to *cache* SmartClient, but not execute it.

    Our FileLoader module handles this neatly when you have the commercial license and that optional module - if not, a quick and dirty approach is to load the files normally such that they are cached, then set a cookie so that you do not load them in subsequent page views. Then, when showing the actual application, load all the files using the evalResult option of RPCRequest. This will be relatively immediate - no server trip.

    Comment


      #3
      Thanks for the tips on cachine--I'll look into it. Unfortunately I'm still having the problem with JQuery. I tried setting window.isc_useSimpleNames to false, but it didn't make any difference. All of my SmartClient function calls and class instantiations were already scoped with the isc prefix. I'll keep fooling with it...

      Comment


        #4
        Try reversing the load order (load JQuery first). Different frameworks are more or less polite in terms of clobbering other frameworks, and JQuery may be clobbering SmartClient functionality.

        Comment


          #5
          Didn't seem to work, but I'll keep fiddling with it. Another piece of the puzzle--the problem only happens in Safari and Chrome.

          Originally posted by Isomorphic
          Try reversing the load order (load JQuery first). Different frameworks are more or less polite in terms of clobbering other frameworks, and JQuery may be clobbering SmartClient functionality.

          Comment


            #6
            Still getting nowhere with this. I discovered that JQuery has its own method for not contaminating other libraries, which I'm now using, but it doesn't help, either. I was hoping I could debug the SmartClient code, but the bug doesn't happen in Firefox (which has a nice js debugger). I was able to make the bug go away by commenting out the "String" function definition in isc_core.js, but the function is called over a hundred times in that file, and I have no way of knowing which caller is causing the problem (short of going through line by line, which I'll probably wind up doing), and of course that breaks the app. Do you have JQuery installed (it's just a single .js file)? If it would help, I could try to make you a very simple test file, and then maybe you could shed some light on what's going on.

            I'm also a bit confused about the cookie/cache trick you mentioned. If I understand correctly, I use RPCRequest.sendRequest to load the cached js files. Do you know of any sample code for this? Seems like there would be kind of a chicken and egg thing, as RPCRequest is itself defined in the same .js files that I need to load.

            Originally posted by shmax
            Didn't seem to work, but I'll keep fiddling with it. Another piece of the puzzle--the problem only happens in Safari and Chrome.
            Last edited by shmax; 30 Sep 2008, 02:39.

            Comment


              #7
              If you can create a simplified test file (or better yet simply make one available) and indicate your exact versions of JQuery and Safari, we can take a look.

              Uh quite right on the bootstrap problem :) Without the benefit of the SmartClient FileLoader you would need to use xmlHttpRequest directly (or via JQuery) to load the SmartClient modules and eval() them.

              Comment


                #8
                Okay, here are two links to test files, stripped down to the bone. The first one demonstrates JQuery working properly. The second is exactly the same, only it includes isc_core.js from the smartclient. View them each in either Safari or Chrome:

                http://www.shmax.com/html/jquery_no_smartclient.html
                http://www.shmax.com/html/smartclien..._conflict.html

                Note that I'm using safe-scoping techniques from both JQuery and SmartClient.

                using latest versions for both libraries:
                SmartClient 6.5.1
                JQuery 1.2.5

                Thanks much for the help...

                Originally posted by Isomorphic
                If you can create a simplified test file (or better yet simply make one available) and indicate your exact versions of JQuery and Safari, we can take a look.

                Uh quite right on the bootstrap problem :) Without the benefit of the SmartClient FileLoader you would need to use xmlHttpRequest directly (or via JQuery) to load the SmartClient modules and eval() them.
                Last edited by shmax; 30 Sep 2008, 06:12.

                Comment


                  #9
                  Hi Shmax
                  Thanks for the example - we're reproducing the issue and have got some way toward determining the cause.
                  One thing that might help - in an earlier post you mention that commenting out some methods on the String object in the SmartClient core was fixing the problem for you. Can you point us to exactly what you were commenting out?

                  Thanks
                  Isomorphic Software

                  Comment


                    #10
                    Hi Isomorphic,
                    After further experimentation I realized that the only reason the commenting was making the problem go away was because the bit of code I was removing was breaking the entire javascript interpreting sequence. In other words, I broke enough of the SmartClient code that whatever bit was corrupting JQuery was itself corrupted. I think. But since you asked, I commented out this piece in isc_core.js:

                    Code:
                    isc.A.String=function(_1){if(_1==null)return false;if(typeof _1==this.$a7)return false;if(_1.constructor&&_1.constructor.$k!=null){return _1.constructor.$k==4}
                    return typeof _1=="string"}
                    I'll dive back in there and see if I can narrow things down a bit better...

                    Originally posted by Isomorphic
                    Hi Shmax
                    Thanks for the example - we're reproducing the issue and have got some way toward determining the cause.
                    One thing that might help - in an earlier post you mention that commenting out some methods on the String object in the SmartClient core was fixing the problem for you. Can you point us to exactly what you were commenting out?

                    Thanks
                    Isomorphic Software

                    Comment


                      #11
                      Well, I've managed to narrow it down a bit. There's a section of code in isc_core.js that executes if the browser is Safari (Chrome apparently evaluates as Safari)--I disabled that block, and everything seems to work. Obviously this isn't a "fix", because the code I'm disabling must have some purpose, but maybe the information can help you fix it properly. Here's the bit I changed (search for "__TEMPF_" to get in the neighborhood):

                      Code:
                         // disable safari check
                         if ( (0 && isc.Browser.isSafari) || !Function.prototype.apply) {
                              isc.A = Function.prototype;
                              isc.B = isc._allFuncs;
                              isc.C = isc.B._maxIndex;
                              isc.D = isc._funcClasses;
                              isc.D[isc.C] = isc.A.Class;
                      Hope that helps.

                      Comment


                        #12
                        Bumpity-bump. I've given up on having my SmartClient app co-exist with the rest of my page content, but I was curious if you guys managed to resolve this?

                        Comment


                          #13
                          Hi Shmax
                          Sorry for the silence on this.
                          The code you disabled is actually almost certainly safe to disable in Safari / Chrome.

                          Early versions of Safari had no native function.apply method so we had to patch it in. It was left active as it is possible to hit a case where nested calls to the native "function.apply()" method can cause Javascript errors. However you have to nest your apply calls very deeply. You're very unlikely to encounter this issue in any "real" use cases.

                          Our engineering team is looking at how best to resolve this for our 7.0 release. We'll be sure to include a fix or workaround as part of that build.

                          Thanks
                          Isomorphic Software

                          Comment

                          Working...
                          X