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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:05:13+00:00 2026-05-18T04:05:13+00:00

I’m working on a google maps loader (using the google maps javascript API). I

  • 0

I’m working on a google maps loader (using the google maps javascript API). I want to dynamically add points to a path as and when they come available. Edit: The webpage and javascript are stored and loaded locally and not through a web server.

To this end I have created an external javascript file in which I put the data I want to use.

I load the java script object using a great trick I found elsewhere on stackoverflow:

function loadjsfile( filename, callback )
{
    var fileref = document.createElement( 'script' );
    fileref.setAttribute( "type", "text/javascript" );
    fileref.setAttribute( "src", filename );

    var done = false;
    fileref.onload  = fileref.onreadystatechange    = function()
    {
        if( !done && ( !this.readyState 
                                || this.readyState == "loaded" 
                                || this.readyState == "complete") )
        {
                done = true;

                // Continue your code
                callback();

                // Handle memory leak in IE
                fileref.onload = fileref.onreadystatechange = null;
                document.getElementsByTagName( "script" )[0].removeChild( fileref );
        }   
    };
    document.getElementsByTagName( "script" )[0].appendChild( fileref );
}

This works perfectly as it waits until the external javascript has actually loaded before proceeding with the intialisation.

So thats all great it loads up fine. I then set a 5 second timeout which reloads the external javascript file. This is where I have an issue. Google chrome is re-loading the external javascript file from cache instead of going straight to disk. This is a huge pain as it means that my map path doesn’t update as it goes along. I really need it to.

When I refreshed the entire page then it was fine it reloaded the javascript but the flicker was very annoying (and it forced the map back to the “initial” state). This new method would work perfectly provided I could force it to re-load the javascript file everytime.

So can anyone help me?

I’m very new to Javascript (I’m mainly a C++ coder) so apologies if I’m asking something stupid 😀

  • 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-18T04:05:14+00:00Added an answer on May 18, 2026 at 4:05 am

    If noone else has other ideas, try appending a random number as a query string to the filename. This will tell the script the file is new and should force a reload.

    Basically generate a random number each time.

    var rnd = Math.floor(Math.random()*80000);
    

    So you code would look something like

    function loadjsfile( filename, callback )
    {
        var rnd = Math.floor(Math.random()*80000);
        var fileref = document.createElement( 'script' );
        fileref.setAttribute( "type", "text/javascript" );
        fileref.setAttribute( "src", filename + "?r=" + rnd ); // note this line
    
        // other code...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.