www.webdeveloper.com
Results 1 to 5 of 5

Thread: Avoid loading Javascript file in iFrames

  1. #1
    Join Date
    Mar 2009
    Posts
    33

    Avoid loading Javascript file in iFrames

    Is there any method to avoid loading js files of iframe. For example, if I loaded jquery from the main (parent) page, and don't want to load an 'extra' jquery of iframe. How could it possible?

    Generally, it is about calling javascript functions in iframes, which is already loaded from parents.

    Thank you very much,

  2. #2
    Join Date
    Mar 2009
    Posts
    33
    Extra comment. The iframe comes from the same URL, so there is no error on SOP.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by catchicken View Post
    Generally, it is about calling javascript functions in iframes, which is already loaded from parents.
    Generally, it is rather a matter of when to use iframes. If it belongs to the same domain, why to load it in an iframe? Can't you use sever-side code includes?

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by catchicken View Post
    Is there any method to avoid loading js files of iframe. For example, if I loaded jquery from the main (parent) page, and don't want to load an 'extra' jquery of iframe. How could it possible?

    Generally, it is about calling javascript functions in iframes, which is already loaded from parents.
    You could try preceding all references to the code with parent. , although there could be circumstances under which the parent code may not be loaded when called by the iframe.

    For instance if you had something like this:
    Code:
    <script type = 'text/javascript' src = 'mysource.js'></script>
    
    <iframe src = 'myfile.htm'>
    
    <script type='text/javascript'>
    
    // run code from 'mysource.js'
    
    </script>
    The content of 'mysource.js' is certain to be loaded when called by the script block below, but I'm not sure that it's guaranteed to be available for the iframe.

    In any case the only extra overhead loading the same file into two pages should be the memory usage, since the file is cached and downloaded only once.

  5. #5
    Join Date
    Mar 2009
    Posts
    33
    Thanks for your answers,

    Actually the browser doesn't cache the script at all (in iframe). Checking with Firebug NET option shows that fact.

    Dear Kor, there are many cases we have to use iframe, especially when the site is highly interactive.

    Quote Originally Posted by Logic Ali View Post
    You could try preceding all references to the code with parent. , although there could be circumstances under which the parent code may not be loaded when called by the iframe.

    For instance if you had something like this:
    Code:
    <script type = 'text/javascript' src = 'mysource.js'></script>
    
    <iframe src = 'myfile.htm'>
    
    <script type='text/javascript'>
    
    // run code from 'mysource.js'
    
    </script>
    The content of 'mysource.js' is certain to be loaded when called by the script block below, but I'm not sure that it's guaranteed to be available for the iframe.

    In any case the only extra overhead loading the same file into two pages should be the memory usage, since the file is cached and downloaded only once.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles