PDA

View Full Version : Single .js file for all the pages.



koder
09-01-2014, 04:33 PM
Hi Frnds,

I have small query.

I have single JS file and i uploaded it in a specific location.

Now i need to call this js file into the pages. But don't want to insert the each and every time into the page. I need to make it dynamic calling from server.

I got idea but i don't know how to do that (or) whether it is possible or not.

Idea: I need to create one xyz.js file, in this xyz.js i need to call another abc.js which i uploaded in specific location. Now i wil inser xyz.js path into the page(main template).

if i changed anythig in abc.js, it will automatically updated in all the pages. In future i won't get any problem.

guys if you didn't understand my issue please let me know i will give example.

jscheuer1
09-01-2014, 08:57 PM
Without specifics, I would recommend simplifying the situation by just using the absolute path to this external .js file, ex (you will want to use https on an ssl if this or the pages it's on are or need to be secure):


<script type="text/javascript" src="http://www.somedomain.com/scripts/abc.js"></script>

Put that in the head of each page, or better still, if you have a server side template, or head include, put it in there.

If it will always be on the same domain as your pages, the network path is preferable:


<script type="text/javascript" src="/scripts/abc.js"></script>

That way either protocol (if available) will be used as necessary.