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 7773743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:12:15+00:00 2026-06-01T17:12:15+00:00

I figured this was a common scenario and was surprised not to find an

  • 0

I figured this was a common scenario and was surprised not to find an answer here. So here it goes…

Some pages within my jquerymobile site are using external javascripts. I don’t want these scripts to load on every page on the site. It’s mobile and it should load fast.

How can I load the external javascript so it is available in the DOM when it needs to be referenced. I found this Stack article which seems to have a good technique: Using Javascript to load other external Javascripts

If I dynamically load this external javascript, should I use the pageinit event? http://jquerymobile.com/test/docs/api/events.html

If I use this event, will the script be loaded in the DOM by the time the page body references it… or will I get an object reference error?

  • 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-06-01T17:12:17+00:00Added an answer on June 1, 2026 at 5:12 pm

    jQuery has the $.getScript() function you can use to retrieve external assets and evaluate them in the global scope. You can utilize the callback function for this AJAX function to do work after an asset has loaded.

    If you want to load multiple assets you can push the XHR object returned from jQuery AJAX functions to an array, then wait for all of the XHR objects in the array to resolve.

    SINGLE

    //get remote asset when a specified page is initialized by jQuery Mobile
    $(document).delegate('#my-map-page', 'pageinit', function () {
        $.getScript('http://maps.google.com/maps/api/js?sensor=false', function () {
            //the code has now been evaluated and you can utilize it here
        });
    });
    

    MULTIPLE

    $(document).delegate('#my-map-page', 'pageinit', function () {
    
        //setup array for XHR objects and one for the URLs of the assets you want to get
        var jqXHRs  = [],
            scripts = ['http://maps.google.com/maps/api/js?sensor=false', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'];
    
        //loop through the script URLs and create an AJAX request to get them,
        //also add the XHR object for the request to an array
        for (var i = 0, len = scripts.length; i < len; i++ ) {
            jqXHR.push($.getScript(scripts[i]));
        }
    
        //use the array of XHR objects we created to wait for all assets to load
        $.when(jqXHR).then(function () {
            //all the scripts have loaded and are evaluated, do work
        });
    });
    

    Some Documentation:

    • $.when(): http://api.jquery.com/jquery.when
    • $.then(): http://api.jquery.com/jquery.then
    • $.getScript(): http://api.jquery.com/jquery.getScript
    • pageInit : http://jquerymobile.com/demos/1.1.0-rc.2/docs/api/events.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've not been able to find anything on this topic, oddly; I figured it'd
I figured this must be a common question, but I surprisingly couldn't find an
I figured this would be simple, but being new to SSRS I'm not sure.
This seems like the most common relationship but for some reason I cannot get
We have some HTML pages (local, not on a web server) that use the
I'm not sure if this even exists or not, so I figured I would
Update II I Figured this out. When using google maps api, the model must
I just figured this out but instead of splitting my new question (why?) into
I thought I had this figured out but it turns out I'm just deleting
I'm pretty close to having this figured out and just need the last bit

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.