slj90 Posted August 31, 2014 Share Posted August 31, 2014 What is the correct order for HTML? <html> <head> <title> </title> </head> <body </body> </html> Where should my css style that isn't on an external css file go? Where should my PHP code go? (E.g session code)Where should my Javascript go?Where should my <no script> go?Many thanks, Quote Link to comment https://forums.phpfreaks.com/topic/290769-html-code-layout/ Share on other sites More sharing options...
CroNiX Posted August 31, 2014 Share Posted August 31, 2014 css/javascript in the HEAD. PHP anywhere (it gets processed before output to browser). noscript where ever you need it (head/body) Quote Link to comment https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1489495 Share on other sites More sharing options...
PrinceTaz Posted September 1, 2014 Share Posted September 1, 2014 <html> <head> <title> </title> Javascript can go here as well </head> <body> <?php echo "PHP can go here"; ?> </body </html> Quote Link to comment https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1489515 Share on other sites More sharing options...
Strider64 Posted September 1, 2014 Share Posted September 1, 2014 (edited) Well I'm going to buck the trend - For best performance place your JavaScript files at the BOTTOM of the HTML page (That way you page can fully load). .... <script>JavaScript</script> </body> </html> Edited September 1, 2014 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1489532 Share on other sites More sharing options...
Jacques1 Posted September 1, 2014 Share Posted September 1, 2014 First the things which (hopefully) everybody agrees on: Put all your PHP code before the HTML markup. Do not mix PHP and HTML, or you'll end up with an unreadable mess of spaghetti code. Put all your JavaScript and CSS into external files. Avoid inline scripts and styles under all circumstances, because those again lead to spaghetti code and prevent the use of effective security tools like Content Security Policy. Where exactly your script elements should be placed is somewhat controversial. Some people say that putting them right before the closing <body> tag will yield the best performance, some say they belong into the head element (possibly with an async or defer attribute for performance). Personally, I always put them into the head, because I think scripts are meta data. Quote Link to comment https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1489541 Share on other sites More sharing options...
deathbeam Posted September 6, 2014 Share Posted September 6, 2014 Here is basic HTML5 layout for you: <!-- PHP code here --> <!doctype html> <head> <meta charset="utf-8"> <title>The Default Template</title> <!-- CSS, favicons etc goes here --> </head> <body> <header> </header> <section> </section> <footer> </footer> <!-- Place your javascript here --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1490173 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.