Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2004, 11:25 PM
Authorized User
 
Join Date: Apr 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pigtail Send a message via Yahoo to pigtail
Default What file extension should I use?

I have several questions:
1. Files with .js can only contain client-side Javascript code and no <%...%> code at all?

2. Whenever I have <% ... %> in my Javascript, I must use .asp in my extension?

3. What should I call the codes within the <%...%>? They look similar to ASP but syntax are different.

 
Old April 11th, 2004, 03:25 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
 
Old April 11th, 2004, 11:23 PM
Authorized User
 
Join Date: Apr 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pigtail Send a message via Yahoo to pigtail
Default

Thank you!!

 
Old April 12th, 2004, 02:58 PM
Authorized User
 
Join Date: Apr 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pigtail Send a message via Yahoo to pigtail
Default

There are many differences in syntax between ASP and server-side javascript. For example, you can't use if .... then in the server-side javascript. It only accepts if (....) { }. There are many other differences too.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to open a pagemaker file with the extension .p yogeshwari_am Visual C++ 0 November 2nd, 2006 07:32 AM
.att file extension??? joffy Intro Programming 1 July 24th, 2006 01:33 AM
Open File with .eml,.msg extension in IE sanjaykp ASP.NET 1.0 and 1.1 Professional 2 April 29th, 2006 02:23 AM
retrive file extension Dj Kat Javascript How-To 2 December 10th, 2005 01:35 PM
File extension detection RichardOrmiston ASP.NET 1.0 and 1.1 Basics 2 November 2nd, 2005 11:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.