Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . External JavaScript file

External JavaScript file

 We can create external JavaScript file and embed it in many html page.

It provides code re usability because single JavaScript file can be used in several html pages.

An external JavaScript file must be saved by .js extension. It is recommended to embed all JavaScript files into a single file. It increases the speed of the webpage.

Let's create an external JavaScript file that prints Hello Javatpoint in a alert dialog box.message.js

  1. function msg(){  
  2.  alert("Hello Javatpoint");  
  3. }  

Let's include the JavaScript file into html page. It calls the JavaScript function on button click.

index.html

  1. <html>  
  2. <head>  
  3. <script type="text/javascript" src="message.js"></script>  
  4. </head>  
  5. <body>  
  6. <p>Welcome to JavaScript</p>  
  7. <form>  
  8. <input type="button" value="click" onclick="msg()"/>  
  9. </form>  
  10. </body>  
  11. </html>  

Advantages of External JavaScript

There will be following benefits if a user creates an external javascript:

  1. It helps in the reusability of code in more than one HTML file.
  2. It allows easy code readability.
  3. It is time-efficient as web browsers cache the external js files, which further reduces the page loading time.
  4. It enables both web designers and coders to work with html and js files parallelly and separately, i.e., without facing any code conflictions.
  5. The length of the code reduces as only we need to specify the location of the js file.

Disadvantages of External JavaScript

There are the following disadvantages of external files:

  1. The stealer may download the coder's code using the url of the js file.
  2. If two js files are dependent on one another, then a failure in one file may affect the execution of the other dependent file.
  3. The web browser needs to make an additional http request to get the js code.
  4. A tiny to a large change in the js code may cause unexpected results in all its dependent files.
  5. We need to check each file that depends on the commonly created external javascript file.
  6. If it is a few lines of code, then better to implement the internal javascript code.

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.

Join Arvind Upadhyay Succedo Event & Movement

Unlock Your True Potential!

Are you ready to transform your life and achieve the success you deserve?

Join us for an empowering experience!

Event Details:

Date: 25th October 2024

Time: 3 PM to 4 PM

Price/Ticket: Rs 100

Virtual Event

Lifetime Guidance

Pay just Rs 100 to join via UPI:

Pay via UPI

Register by emailing: ceoarvindenterprises@gmail.com

Chat with our team on WhatsApp for more information:

918080772353

Register Now Chat on WhatsApp

Event by Arvind Upadhyay.

Arvind Upadhyay is the author of over 100 books, a business and life coach, and famous for his self-help books, high-energy seminars, and workshops.

Attract Health, Wealth, and Success

Using the Law of Attraction

Are you struggling to become successful, despite having all the knowledge and skills?

It might be because you’re not using the most powerful principle known to mankind.

Join Our Virtual Event!

Available in Hindi and English

Date: 20th Oct 2024

Time: 10 AM to 11 AM

Pay just Rs 50 to join via UPI:

Pay via UPI

Register by emailing: ceoarvindenterprises@gmail.com

Chat with our team on WhatsApp for more information:

918080772353

Register Now Chat on WhatsApp

Event by Arvind Upadhyay.

Arvind Upadhyay is the author of over 100 books, a business and life coach, and famous for his self-help books, high-energy seminars, and workshops.