此内容来自第三方平台 (Dailymotion)。如果此视频侵犯了您的版权,请使用 立即删除 工具。
Inline vs external javascript
描述
In this video we will discuss
1. Different places where JavaScript can be present
2. Advantages of external JavaScript over inline JavaScript
JavaScript can be stored either inline on the page or in an external .js file. Let's look at an example of both the approaches.
Inline JavaScript example : In this example, IsEven() JavaScript function is present inline on the page.
function IsEven()
{
var number = document.getElementById("TextBox1").value;
if (number % 2 == 0)
{
alert(number + " is even number");
}
else
{
alert(number + " is odd number");
}
}
Number :
External JavaScript example : Steps to store JavaScript in an external .js file
1. In Visual Studio, right click on the project name in Solution Explorer and select add select Add => New Item
2. From the "Add New Item" dialog box select "JScript File". Name the file "ExternalJavaScript.js" and click Add.
3. Copy and paste the following JavaScript function in the "ExternalJavaScript.js" file
function IsEven()
{
var number = document.getElementById("TextBox1").value;
if (number % 2 == 0)
{
alert(number + " is even number");
}
else
{
alert(number + " is odd number");
}
}
4. On your webform in the head section include a reference to the external JavaScript file using script element as shown below
Advantages of external JavaScript over inline JavaScript : Here are some of the general advantages of external JavaScript over inline JavaScript
Maintainability : JavaScript in external files can be referenced on multiple pages without having to duplicate the code inline on every page. If something has to change, you only have one place to change. So external JavaScript code can be reused and maintenance will be much easier.
Separation of Concerns : Storing JavaScript in a separate external .js file adheres to Separation of concerns design principle. In general it is a good practice to separate HTML, CSS and JavaScript as it makes it easier working with them. Also allows multiple developers to work simultaneously.
Performance : An external JavaScript file can be cached by the browser, where as an inline JavaScript on the page is loaded every time the page loads.
1. Different places where JavaScript can be present
2. Advantages of external JavaScript over inline JavaScript
JavaScript can be stored either inline on the page or in an external .js file. Let's look at an example of both the approaches.
Inline JavaScript example : In this example, IsEven() JavaScript function is present inline on the page.
function IsEven()
{
var number = document.getElementById("TextBox1").value;
if (number % 2 == 0)
{
alert(number + " is even number");
}
else
{
alert(number + " is odd number");
}
}
Number :
External JavaScript example : Steps to store JavaScript in an external .js file
1. In Visual Studio, right click on the project name in Solution Explorer and select add select Add => New Item
2. From the "Add New Item" dialog box select "JScript File". Name the file "ExternalJavaScript.js" and click Add.
3. Copy and paste the following JavaScript function in the "ExternalJavaScript.js" file
function IsEven()
{
var number = document.getElementById("TextBox1").value;
if (number % 2 == 0)
{
alert(number + " is even number");
}
else
{
alert(number + " is odd number");
}
}
4. On your webform in the head section include a reference to the external JavaScript file using script element as shown below
Advantages of external JavaScript over inline JavaScript : Here are some of the general advantages of external JavaScript over inline JavaScript
Maintainability : JavaScript in external files can be referenced on multiple pages without having to duplicate the code inline on every page. If something has to change, you only have one place to change. So external JavaScript code can be reused and maintenance will be much easier.
Separation of Concerns : Storing JavaScript in a separate external .js file adheres to Separation of concerns design principle. In general it is a good practice to separate HTML, CSS and JavaScript as it makes it easier working with them. Also allows multiple developers to work simultaneously.
Performance : An external JavaScript file can be cached by the browser, where as an inline JavaScript on the page is loaded every time the page loads.
相关视频
30 Cascading External, Internal and Inline CSS - Beginner's Web Designing (Urdu)
Hammad Syed
CSS3 PROGRAMMING - Tutorial 4 | CSS - How to Add CSS (Internal, External & Inline)
ComputerScienceVideos
Introduction to CSS,Types(inline,external,internal) in URDU -moixx web-
Moixx Web
Style Tag | Inline Styling | External Stylesheets
Web Artificer
HTML5 canvas tutorial Images using inline css & javascript in Urdu Hindi
Ifactner
27 Inline, Internal and External CSS - Beginner's Web Designing (Urdu)
Hammad Syed