Skip to main content
About Us

JavaScript

TL;DR

JavaScript is a popular programming language mainly used to insert dynamic elements into a website.

What is JavaScript?

JavaScript is a programming language, mainly used to insert dynamic elements into web pages. Examples of dynamic elements include automations, animations, interactive elements, traffic counters, etc. Without JavaScript, websites would be static, relying only on HTML and CSS. JavaScript is usually embedded in the HTML code of a web page or it can function in a separate file that is linked in the <head> section of HTML:

  • Example of linked Javascript: <script src="/js/assets/example.js" type="text/javascript"></script> 

  • Example of embedded (inline) Javascript (this example is the script Visitor Analytics uses in order to be able to track website statistics): <script>(function(v,i,s,a){if(!v._visaSettings){v._visaSettings={};}v._visaSettings["326865a9-6d58-11e8-834c-0242ac120005"]={v:"0.3",s:"326865a9-6d58-11e8-834c-0242ac120005",a:"1"};_v=i.getElementsByTagName("head")[0];_a=_v;_i=i.createElement("script");_s=_i;_s.defer="defer";_s.src=s+a+v._visaSettings["326865a9-6d58-11e8-834c-0242ac120005"].v;_a.appendChild(_s);})(window,document,"//app-worker.visitor-analytics.io/main",".js?s=326865a9-6d58-11e8-834c-0242ac120005&v=")</script>

Why am I being asked to add JavaScript code to my website?

Many times, if you use a tool to enhance your website, it will ask you to copy-paste a JS <script> into your dashboard, so that it is displayed in the <head> of the HTML. If you trust the provider of the tool, this should not be a problem. This is something that the specified service needs in order to be able to add a certain functionality to your website. If you use a web building platform, like Wix or Wordpress or others, and install an extension or a plugin, it will often automatically add the needed JavaScript to your website. In some cases, you may still need to manually copy-paste a code into the header.

JavaScript issues and solutions

If you install too many plugins/extensions on a website, they could insert a great deal of JavaScript codes into the header. There are examples where a web page references more than 60-70 external JavaScript files in the <head> section. Before loading any content, the web browser will try to download all of these resources, slowing down the page load time significantly. There are several solutions for this, one of them being described in the dynamic rendering glossary entry.