Web Front-End Programming
Javascript In the web browser
Where to put your browser-based is a programming language, that has two main uses:
Copyright By PowCoder代写 加微信 powcoder
1. Javascript used to manipulate the DOM in a web browser (discussed in another lecture)
2. Javascript used to write scripts with NodeJS (discussed in another lecture)
Today we are focusing on (1).
More specifically, what are the different ways you can include your Javascript in a page run by a web browser?
HOW code is included
Code can either be included inline (part of the page) or included via external link (URL to resource)
inline external
1
mypage1.html
mypage2.html
1
1 const a = 1 + 2; 2 console.log(a);
HOW code is included
Linking javascript externally:
Improvements performance when browser cache is utilised Reduces the time it takes for initial html document to be received (smaller file)
Placing Javascript inline:
Avoids network requests (potentially costly) for script if file is not yet loaded
WHERE code is included
1 2 3 4 5 6 7 8 9
Generally speaking you can either:
1. Include in the
2. Include at the end of if you need do not need your javascript to run prior to your DOM elements initially rendering
We usually do (2)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com