Javascript 哪一个更好:在调用脚本时使用Include或src?

Javascript 哪一个更好:在调用脚本时使用Include或src?,javascript,php,include,require,src,Javascript,Php,Include,Require,Src,好的编码实践应该是什么 代码1 或 代码2 更快、更可靠。通过PHP加载肯定会慢很多。尤其是当存在多个其他PHP请求时。更好。Javascript将被加载并作为缓存保存在客户端计算机中。所以它将从客户端计算机的缓存中调用代码。但PHP代码将从服务器加载代码,这会使服务器运行速度变慢,并且服务器的工作也会变得更加困难。 <script src="js/sample.js" type="text/JavaScript"></script> it is the corr

好的编码实践应该是什么

代码1


代码2


更快、更可靠。通过PHP加载肯定会慢很多。尤其是当存在多个其他PHP请求时。

更好。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.
这是正确的语法。W3C建议这是链接JavaScript文件的标准语法。 快速加载JavaScript文件。和SEO优化您需要定义的脚本类型。
取决于上下文。从外部加载是另一个网络请求,但该请求可以缓存。可以肯定-这有意义吗?
<script>

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

</script>
<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.