0

Currently I have an website where each page on the site has a corresponding js file that contains a class (well function) defined in it. Currently when the user navigates to another page (which is just ajax content) I remove the old script tag from the page and add a new script tag for the new page. This is working though I was wondering if there could be any problems with this or better ways to do it? I've been thinking of using an AJAX call (XMLHTTPRequest) to get the new js file then using eval to initiate the new page.

asked Apr 7, 2015 at 16:10
2
  • When you say "unloading" what do you mean? The code has already been executed, so removing the <script> would make no difference, right? Commented Apr 7, 2015 at 16:13
  • by unloading I'm removing the script tag because the new content displayed on the page no longer needs that .js file. Also all references to the javascript loaded from that .js file are nulled out. Commented Apr 8, 2015 at 16:37

1 Answer 1

1

What you are doing makes sense because the browser can intelligently cache the js.

Getting the js yourself might prevent the possibility to cache.

answered Apr 7, 2015 at 16:13
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.