Normally, a .
js file is referenced from HTML by a <script> tag. This serves two useful purposes that I can see:
A) It allows the developer to modularize commonly used javascript in a single file that can be referenced by many pages
B) It allows the browser to cache that file just like it can cache HTML so that the whole file doesn't need to be retrieved every time a page is loaded that uses it. This results in a faster page load.
Answers to your questions:
1) You could certainly put ASP <%...%> in a .
js file, but it would not get processed by the ASP engine (unless you modified the configuration on IIS to process
JS files with the ASP processor). Now, this is not to say that you can't make a javascript source file that has ASP processing. See next answer.
2) You can put ANYTHING in the src attribute of the script tag (<script src="mydynamicjs.asp">). As long as the output is valid javascript, that's all the browser cares. This allows for "dynamic" javascript files, however, you must pay close attention to comment (B) above. Because the resource of the src attribute is often cached, you may not get truly dynamic-every-time javascript. Also remember that this resource request to the server is completely isolated from the ASP request that draws the resulting HTML that contains the script tag. Every HTTP request is separate and unrelated. So you can't share page execute information. However, you should be able to share session information. However (again), if the code that runs to generate the javascript tries to tell the browser something (like cookies) it may not work. I can't say I've ever tried having an ASP generate JavaScript and also write out cookies so I can't be sure.
3) What do you mean the syntax is different? Isn't it still ASP code? What could you put between <% %> that isn't ASP?
Peter
-------------------------
Work smarter, not harder