0

I am experiencing some issue when loading some javascript file. I am using some jquery plugin and to make it work, I had to add the several required javascript files just before the closing body tag. Now I want these files to be loaded for some specific url, so I tried this

    $(document).ready(function(){
if(window.location.href.indexOf("some url") > -1) {
$.getScript("my_different_files.js");}
});

but now the plugin doesn't work (I won't detail the error because I only changed the javascript files loading process). What is the best way to mimic the javascript source loading using some url conditioned load ?

4
  • have you tried loading the script synchronously ? Commented Aug 2, 2013 at 12:07
  • @collapsar yes, same result ! Commented Aug 2, 2013 at 12:08
  • have you checked the contents of window.location.href and <some_url>at the time of calling? maybe some problem with url encoding of reserved characters? Commented Aug 2, 2013 at 12:10
  • @collapsar yes I checked, it works well Commented Aug 2, 2013 at 12:14

2 Answers 2

1

A better approach for such a task would be to use some module loading/management library like RequireJS. This is some example code on how you can do that with RequireJS

Sign up to request clarification or add additional context in comments.

1 Comment

thank you but how do I specify some specific js file load for a specific uri with requireJs. (Because I am using smarty which generate first header and footer and then loads the content. If I put my js files in the content that is loaded after header and footer, the jquery plugin fails to work
0

You can try these tips..i think it will suit to you.

Comments

Your Answer

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.