javascript - The main difference between internal js file and external js file -
is there different between include external js file , write down javascript in html page.
case 1
test.html
<html> <head> <script type="text/javascript" src="test.js"></script> </head> <body> </body> </html>
test.js
alert('aaa');
case 2
test.html
<html> <head> <script> alert('aaa'); </script> </head> <body> </body> </html>
case 1 execute more faster case2 if memory services me right. not sure. moreover, cannot find relative documents or articles support ideal. may me?
case 1 is slower @ first, because needs second request script, there little overhead.
however, browser cache javascript file, if have multiple pages share same script, case 2 more efficient, because subsequent pages, browser has cached script , doesn't need download again.
also, browsers allow opening 2 connections same server, may download page , script simultaneously on first request, although depends on size of page , script, server, client , internet properties (latency , speed) solution faster.
Comments
Post a Comment