Ok to include css and js files outside of <html>?

I wonder if I can embed js and css files over the area of ​​the html document:

<script type="text/javascript" src="../../media/js/jquery.js"></script>
<script type="text/javascript" src="../../media/js/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="../../media/css/cupertino/jquery-ui.css" />

<html>
   <head>
   </head>
   <body>
   <body>
</html>

this is because I want to put them in the same php file where I include all the files (php, js and css). I tried this and it seems to work. the output of the html file will be shown in the same way as the above code, including the lines above the html tag.

Are there any hidden disadvantages to this?

+3
source share
6 answers

, . , . , . , .

+10

html. javascript ( , ). .

+6

(X) HTML.

+5

, , . .

HTML , , , , no promises, . - , , .

+2

, ? "", , <html>. - :

include.php:

<?php 
ob_start();
// here is where you output your css and js declarations
$includes = ob_get_clean();
?>

:

<html>
 <head>
  <title>Hello</title>
  <?php echo $includes ?>
 </head>
 <body>
 ...
+1

, , , Google .

Take a look at this: https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery#example

Any thoughts on why Google favors incorrect HTML coding?

0
source

Source: https://habr.com/ru/post/1730808/


All Articles