Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global Javascript files and naming conventions (unobtrusive Javascript)?

I am trying to reorganize my Javascript into JS files and clear out my js from my html... The way I see if is the following.... I would really like some input or any documentation/information confirming my plans - a little uncertain.

Basically if I have a Home.htm file then I will have a home.js file also, notice they are named the same. The home.js will be like the bootstrapper for that page and will assign events (onclick etc)...

I was planning on doing this with all files i.e. login.htm > login.js ...

I was also thinking about have a global.js file which will be included in EVERY page that contains items that are needed in every file..

I also plan on having other js files which I plan on producing in a namespace so that my bootstrapper files can call classes in that namespace to do things like date manipulation etc.. I know JS is not a true OOP language but i have some helper js which allow to create namespaces and better class structures.

Does anyone have a better idea? Am completely going in the wrong or right direction?

I would really like some input, I am trying to separate all my js into separate files but I don't want to repeat myself so I thought of creating those bootstrapper files to take care of everything for the page..

like image 627
mark smith Avatar asked Oct 24 '09 15:10

mark smith


People also ask

What is the naming convention for JavaScript files?

File names must be all lowercase and may include underscores ( _ ) or dashes ( - ), but no additional punctuation. Follow the convention that your project uses. Filenames' extension must be . js .

What is the meaning of unobtrusive JavaScript?

In short, unobtrusive JavaScript is a way of writing JavaScript so that your site visitors are not shut out of your site for one of these reasons—even if your JavaScript is not working correctly for them, they should still be able to use your site, albeit at a more basic level.

What is the meaning of unobtrusive JavaScript explain us by any practical example?

Unobtrusive JavaScript is a general approach to the use of client-side JavaScript in web pages so that if JavaScript features are partially or fully absent in a user's web browser, then the user notices as little as possible any lack of the web page's JavaScript functionality.

Which of the following are the benefits of using unobtrusive JavaScript?

There are several benefits of using Unobtrusive JavaScript. Separation of concerns i.e the HTML markup is now clean without any traces of javascript. Page load time is better. It is also easy to update the code as all the Javascript logic is present in a separate file.


1 Answers

Depending on how you go about it, I think the idea itself is quite reasonable. Namespacing your JS code in an OOP-like fashion is a good idea, and many libraries such as YUI and Dojo already do it.

like image 185
Jani Hartikainen Avatar answered Oct 23 '22 11:10

Jani Hartikainen