Does javescript files need the .js extension?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Does javescript files need the .js extension?

Post by JellyFish »

It was interesting, when I changed the file extension of one of my JavaScript files to ".cl" it had no effect on my JavaScript file.

Aren't JavaScript files just text files? So why do they need the ".js" file extension in the first place? I guess it's a way to recognize the the file as a JavaScript file, in Windows Explorer. But other then that it's not necessary, is it?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The <script> tag defines the file type, not the extension. JavaScript isn't server-side, so the server doesn't handle the parsing, the browser does.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

superdezign wrote:The <script> tag defines the file type, not the extension. JavaScript isn't server-side, so the server doesn't handle the parsing, the browser does.
Exactly. Which is why I don't see why JavaScript needs any particular file extension, for that matter.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

most things don't NEED their extension. It would be kind of lame to try and figure out what belongs to what all the time if you didn't assign extensions to them
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

The Ninja Space Goat wrote:most things don't NEED their extension. It would be kind of lame to try and figure out what belongs to what all the time if you didn't assign extensions to them
True. Extensions are necessary when it comes to that. But I'm was thinking of taking more of a Java approach with JavaScript by making my javascript files that define a class with the extension of ".cl".
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

how about to make it easy on yourself... try filename.cl.js -- then you get the best of both worlds.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

The Ninja Space Goat wrote:how about to make it easy on yourself... try filename.cl.js -- then you get the best of both worlds.
I was thinking that. It might be more semantic in that manner.
Post Reply