Conditional Javascript loading

Discussion in 'JavaScript' started by Nick_Mayhem, Jul 7, 2008.

  1. #1
    Hello :)

    I have a scenario where the Javascript libarary is loaded from an external source.

    But if the code is repeated on the page. Then it loads the libraries more then once.

    Can someone help me with some javascript code that will only allow the libraries to be loaded once.

    It could be something like it can check if it is loaded and if it is loaded then it should not load it again.

    But I don't know how to implement that.

    Thanks.
     
    Nick_Mayhem, Jul 7, 2008 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well maybe show us what you already have, then it will be easier for us to help you, anyway why not load javascript in the <head> section and never think again about loading it again?
     
    Greg Carnegie, Jul 8, 2008 IP
  3. Nick_Mayhem

    Nick_Mayhem Notable Member

    Messages:
    3,486
    Likes Received:
    338
    Best Answers:
    0
    Trophy Points:
    290
    #3
    No it was not possible to load it in Head tags as the sites where this will be loaded will not be controlled by me.....

    But as of now I have found a way to set a flag to true if library is loaded and if the flag is true then don't load the library.
     
    Nick_Mayhem, Jul 8, 2008 IP