mm22 0 Report post Posted November 4, 2008 So I've built my first PHP&Mysql based website, enjoying it very much Although it's a simple website (still developing!) it includes a decent looking css powered interface, navigation buttons, user login system, session control and so on.Now, I haven't used a single line of Javascript so far, other than looking it up a little I have no real knowledge of it. What I know is that it is a browser side script and as such its instructions are not concealed in a web page source file. Javascript commands are interpreted by the browser and, unless the user deliberately blocks them, he or she has no clue about what's going on.In my browsing experience I find heavy usage of Javascript quite annoying, it clogs up the browser and sometimes the browser itself refuses to correctly interpret the commands (i.e. problems with different browsers). I have noticed (by looking at the Status Bar when hovering over a link) that many seemingly ordinary links have a Javascript instruction attached to them.My question is: is such use of Javascript really necessary? or at least a definite advantage? I figure that if someday I were to put some JS in my design it would be to show/hide things (like the Fast Reply box in Trap...) or open popups if necessary. It seems to me most other jobs can be easily done by a server side script, like PHP.As I said I'm all but experienced so I'd be glad to anyone giving some advice on this matter, like pointing out a few pros and cons of using JS and where it really comes into hand.Thanks Share this post Link to post Share on other sites
xpress 0 Report post Posted November 4, 2008 (edited) Even though some disadvantages are there, client side scripting(e.g, javascript) has lot more advantages. As you told you can do most of the the things with php that javascript do. But you do them at the cost of speed and comfort. Because javascript runs at client side, and php runs at server side. And there are many things you cannot do with server side scripting. Some Advantages: One of the best example for this is Form Validation. When a user types something wrong in a field or left some necessary field blank, javascript will tell it immediately and forces the user to correct his mistakes. If you want to do it with PHP, the user have to submit the page to server and server processes it and will tell there are mistakes, and the user have to correct them and then submit again. This have to done again and again until the user correct all his mistakes. What a waste of time and discomfort? The next advantage of clent side scripting is better user interactivity. You can use RollOvers, Drop down menus and Popup menu's etc... You have to use client side scripting like javascript for these. The third advantage is it saves server resources. Right. As in first example if you have to process the page again and again there will be some unnecessary bandwidth wastage as well as unnecessary wastage of proecessing power of server. If you save them you can serve more users. It is better to leave them to client side, isn't it ? Many more advantages are there. Some Disadvantages: Of course, there are some disadvantages. The main one is, if the user disables scripting your site will give annoying experience to user. But these are rare cases for average users. And a security problem is, the user can bypass the client side scripting for validation. Thus he can abuse the server. So you must have server side validation of the page along with the client side validation. Since the client side scripting is there, usually the server side validation will run only once. So no precious waste of server resources. Hope my post helps you, if not or if you have any more doubts ask me... Edited November 4, 2008 by xpress (see edit history) Share this post Link to post Share on other sites
Mordent 0 Report post Posted November 4, 2008 So I've built my first PHP&Mysql based website, enjoying it very much Although it's a simple website (still developing!) it includes a decent looking css powered interface, navigation buttons, user login system, session control and so on. Now, I haven't used a single line of Javascript so far, other than looking it up a little I have no real knowledge of it. What I know is that it is a browser side script and as such its instructions are not concealed in a web page source file. Javascript commands are interpreted by the browser and, unless the user deliberately blocks them, he or she has no clue about what's going on. In my browsing experience I find heavy usage of Javascript quite annoying, it clogs up the browser and sometimes the browser itself refuses to correctly interpret the commands (i.e. problems with different browsers). I have noticed (by looking at the Status Bar when hovering over a link) that many seemingly ordinary links have a Javascript instruction attached to them. My question is: is such use of Javascript really necessary? or at least a definite advantage? I figure that if someday I were to put some JS in my design it would be to show/hide things (like the Fast Reply box in Trap...) or open popups if necessary. It seems to me most other jobs can be easily done by a server side script, like PHP. As I said I'm all but experienced so I'd be glad to anyone giving some advice on this matter, like pointing out a few pros and cons of using JS and where it really comes into hand. Thanks I've recently finished my first PHP / MySQL-based site myself (well, a site is never truly "finished", but you know what I mean...), so I'm a similar boat to you in that respect. JavaScript is, in my opinion and from what I've read , never necessary as such, but good use of it can certainly make for a better site overall if used well. The obvious advantage is that by using JavaScript you can reduce the strain on your web server by not having to load a page over and over, and perform, as xpress mentioned, simple validation of input and the like. Naturally this isn't a replacement for server-side validation, merely a means of requiring just one loading of a page for a majority of users. Perhaps one of the most promising and tempting feature of JavaScript I've seen so far is in the implentation of AJAX (or Asynchronous JavaScript And XML), which is certainly on my list of things to look at once I've delved in to JavaScript's basic. It's certainly something to work towards, anyway. Hope this helped! Share this post Link to post Share on other sites
mm22 0 Report post Posted November 5, 2008 Thanks a lot xpress and Mordent, very helpful posts :lol:It is pretty much as I expected, i.e. not necessary but highly recommended for many common tasks like validation and user experience enhancement.Good you mentioned the double-validation practice (JS plus server-side) to avoid rare but undesirable results!So next, go learn JavaScript and AJAX! have seen that word many times and always pretended to know what it means, but aside from the intriguing acronym I have no real idea of what it means Share this post Link to post Share on other sites
xpress 0 Report post Posted November 5, 2008 (edited) You're welcome mm22. And about AJAX....it stands for Asynchronous Javascript And XML...It is a combination of different technologies like Javascript, XML, DHTML, CSS etc... AJAX can make your site much more interactive and interesting. It will give your user a desktop application feel with your website. That means....no need to refresh or reload whole page to see changes in the page. The changes will appear in realtime just like a desktop application. And the best thing of AJAX is you don't need any plugins for this. It will work with normal webbrowser. A famous example for AJAX is GMaps (Google Maps). Have you ever used it? You'll see the changes immediately in the map whn you move it with your mouse... Thats the power of AJAX. Actually the concept behind it is, AJAX engine. When you request for a page with AJAX, the browser loads the AJAX engine. This works as a mediator between the browser and server. When you click or type, it will generate an event and Ajax engine will communicate to server and updates your page with response. All this is done in the background. The Ajax engine will continuously refresh the page content without refreshing the whole page. So the results are realtime. Edited November 5, 2008 by xpress (see edit history) Share this post Link to post Share on other sites