哪个更好:在调用脚本时包含或 src


Which is better: Include or src in calling a script?

好的编码实践应该是什么?

代码1

<script src="js/sample.js"></script>

代码2

<script>
    <?php include('js/sample.js'); ?>
</script>

<script src="js/sample.js"></script> 更快、更可靠。 通过 PHP 加载肯定会更慢。 特别是当有多个其他 PHP 请求时。

<script src="js/sample.js"></script>更好。Javascript将被加载并保存在客户端计算机中作为缓存。因此,它将从客户端计算机中的缓存中调用代码。但是PHP代码会从服务器加载代码,这使得它变慢,你的服务器会更努力地工作。

<script src="js/sample.js" type="text/JavaScript"></script> 
it is the correct syntax. W3C recommend this is a standard syntax for linking JavaScript file.
fast loading JavaScript file. and SEO optimization you required to define type of script.