Jump to content

Html Coded Vs. Javascript Or Php Generated


shadowayex

Recommended Posts

I have a few drop down menus that have values and whatnot that fall in order by number (1, 2, 3, etc.). I thought about instead of typing each out, using PHP to generate the menus for me. This woudl pretty much give the same effect as it would if I typed it, except that PHP would have to do it, which I thought make take more loading time.From there, I thought maybe let JavaScript do it. I figured whatever time it would take for JavaScript to do it would be counter-balanced by the drop in data having to be transfered between server and client. But then my site becomes even more reliant on JavaScript being enabled. It is already mostly JavaScript dependent, but it can be used if JavaScript isn't enabled. It'd just be boring and less user-friendly.What are everyone's thoughts, HTML coded, PHP genereated, or JavaScript generated; what would be better for the user? Or is it a case by case dependency. If so, what would be best in this case?

Link to comment
Share on other sites

If stuff is likely to change, for example if you have a product category menu and you need to make sure you have a link to a category page for each category, you can have PHP fetch the categories from your product database, that way you never have to worry about keeping your menus up to date. If you only have to do something once or twice, and it will remain relevant and applicable for the foreseeable future, hard code it. I try to avoid javascript for anything that isn't non-essential. My current site menu opens and stays open when you click it, and the right top level menu item displays a different color than the rest, but without javascript the page breaks gracefully and a simple menu appears - it looks identical but works differently - and the current tab isn't dark blue, but it's stuff nobody will notice unless they're looking or have experience of the site on a better browser. That's my general principle: javascript for anything glitzy and unessential, PHP for anything that will change depending on users being logged in or that involves a db, and hard code everything else. The real overlap is to use PHP to include your menus, headers, footers, etc., so that if you make changes, you make them once. That's kind of dynamic and hard coded..

Link to comment
Share on other sites

I see where you're coming from. I have a header on my site that is included using PHP. As I said, the JavaScript I do use isn't 100% essential, it's just nice. I see your point about JavaScript. It's probably a safer bet to avoid using it.But hard-coded vs. PHP generated, aside from what does the writing, is there a whole lot of difference between the results?

Link to comment
Share on other sites

No, because the PHP will just generate HTML, so you end up with the same thing anyway...

Link to comment
Share on other sites

So in this case, hard-coded would be the best route? Since using PHP will make for a slightly slower loading time for the same result, I'd assume.
In your case (as described so far), yes. But again, if the menu is likely to change in the future or is dependant upon another piece of data (e.g. something in a database), it should be generated with PHP. Even though PHP generation would be slightly slower, it will reduce A LOT the time you'll need to update the dropdown and everything related (if anything).
Link to comment
Share on other sites

Oh I know. It's just a menu that has all the years from 1902 to the present. It'll only be updated once a year :). I appreciate your help and advice. General purposes for what should be PHP generated and what shouldn't be makes more sense to me now.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...