Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a javascript file (called secure.js that has several functions defined in it. I also have a Visual Studio solution with ten different ASP.NET web applications. I want to be able to call the javascript functions in secure.js from aspx pages in all of my applications.

Do I have to copy the .js file into a directory under each of the applications, and in my aspx pages reference the secure.js file that is local to that application? Is there a way to serve up the javascript file from a single location (something like jQuery being referenced from a CDN)?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can call that same file from a full URL and have it used in every/many applications without it physically being present in the file structure of each application.

<script src="http://www.someotherwebsite.com/secure.js"></script>

Remember, JavaScript files, just like CSS files or images are resources that are downloaded separately from the main HTML file. They do not have to be part in the same file structure or in the same domain as the main HTML file. In fact, if you place your JavaScript files in a CDN or a subdomain or a different domain altogether you will probably speed up the performance of your application.

share|improve this answer
    
only question, say i put it in a scripts directory under my site root (e.g. www.mysite.com/scripts/secure.js) and reference it from there.. are there any potential security concerns with doing so? –  mhornfeck Jan 26 '12 at 22:27
    
No, there would be no security issues from this. –  John Conde Jan 26 '12 at 22:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.