Inline vs. External Javascript

本文讨论了将JavaScript代码置于外部文件中的好处,特别是从维护和性能的角度出发。通过示例展示了如何将内联脚本转换为外部文件,并解释了外部脚本能够更容易被浏览器缓存,从而提高网页加载速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Inline Code 

<html>
<head> 
<script type="text/javascript">
function a()
{
alert('hello world'); 

</script>
</head>
<body>
 :
:
</body>
</html>

External Files 
<html>
<head> 
<script type="text/javascript" src="/scriptone.js">
</script>
</head>
<body>
 :
:
</body>
</html>
scriptone.js
function a()
{
alert('hello world'); 
}


The rule is simple: All script should be external. Both for maintenance and performance.

(Why performance? Because if the code is separate, it can easier be cached by browsers.)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值