Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1079623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:53:56+00:00 2026-05-16T21:53:56+00:00

I am using the following technique to load up Javascript dynamically: var script =

  • 0

I am using the following technique to load up Javascript dynamically:

var script = document.createElement("script");
script.type = "text/javascript";
script.src = "file.js";
document.body.appendChild(script);

It’s quite a common approach.
It’s also discussed here: http://www.nczonline.net/blog/2009/06/23/loading-javascript-without-blocking/

I know how to get notified once the file has been loaded and executed

What I don’t know is that if the link to the Javascript source file is broken how can I be notified.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:53:57+00:00Added an answer on May 16, 2026 at 9:53 pm

    Listening for events on script elements is not considered reliable (Source). One option that comes to mind is to use setTimeout() to poll for a variable that you expect to be defined in your external script. After x seconds, you could timeout your poll and consider the script as broken.

    External Script: file.js:

    var MyLibrary = { };
    

    Main document:

    var poll;
    var timeout = 100; // 10 seconds timeout
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'file.js';
    document.body.appendChild(script);
    
    poll = function () {
      setTimeout(function () {
        timeout--;
        if (typeof MyLibrary !== 'undefined') {
          // External file loaded
        }
        else if (timeout > 0) {
          poll();
        }
        else {
          // External library failed to load
        }
      }, 100);
    };
    
    poll();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I used to use ERB templates everywhere using the following technique: def create_from_template(file, template,
When using a standard asp:Button component, it is necessary to use the following technique
Using following code I try to get updated list of checkbuttons' corresponding text values,
I am using following command for start the production server. nohup ruby script/server webrick
I'm implementing Comet using the script tag long polling technique, based on this page
I am looking into using Buffer Strategy and the following technique described on the
At Linux the following technique can be used to auto-remove file at process exiting:
I'm using the following technique to set a wild-card cookie for our domain: cookies['root_domain_flash_warning']
Challenge: Please create an instance of the following class (using any type as T):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.