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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:48:47+00:00 2026-06-03T13:48:47+00:00

I know that, once a script has loaded, you can remove the <script> element

  • 0

I know that, once a script has loaded, you can remove the <script> element from the page and the variables/functions will still be there.

Let’s say I have two versions of a function, dealing with UI and which the user can choose between based on preference.

The whole page is heavily AJAX-based. Ideally, it should never reload unless explicitly done by the user, so calling location.reload() is simply out of the question.

The idea I have is this:

<script type="text/javascript" src="ui1.js" id="uiscript"></script>

Then simply change:

document.getElementById('uiscript').src = ...;

Both files are of the form:

var ui = function(...) {
    ...
};

So my question is, would toggling between two sources change the function reliably? Even if the script is cached? Would I be better adding a cachebusting query string? Or should I abandon this idea altogether and go for something else, such as rewriting the function in a callback rather than changing a script’s source?

Any other suggestions on something like this?

  • 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-03T13:48:48+00:00Added an answer on June 3, 2026 at 1:48 pm

    Why don’t you use a reference to the function? Some pseudo code here:

    function func1() { /* Do stuff one way */}
    function func2() { /* Do stuff the other way */}
    var ui = func1;
    
    ui(some_param);
    
    function myCallback() {
      // overwrite ui
      ui = func2;
      ui(some_param); // now calls func2
    }
    

    This is just a simple example. In the real world you’d use Objects to group your functions together.

    Maybe you can use a dependency injection framework for JavaScript like inject

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a web page that has a from field that allows a user
I know the location of the DerivedData folder that Xcode creates once I build
I know that it's a subject that can raise a lot of debate, but
We know that behind the scenes, the ASP.NET MVC framework will use reflection to
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
I know that this has already been asked here but the answer (using a
i have some jquery script which runs after the window has loaded $(window).load( function()
I need to execute from Java a batch script, which does following 1) Once
I have got an iframe that displays a form from an external site,once the
I have a table that will have 500,000+ records. Each record has a LineNumber

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.