Skip to main content

Javascript

TL;DR

Javascript is a popular programming language mainly used to insert dynamic elements in a website.

What is Javascript?

Javascript is a programming language, mainly used to insert dynamic elements to 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 an HTML:

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

  • Example of embedded (inlined) 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 insert a Javascript code into 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 constitute 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, that will most times automatically add the needed Javascript to your website. In some cases, you may still need to manually copy-paste a code in the header.

Javascript issues and sollutions

If you install too many plugins / extensions on a website, they could insert a great deal of Javascript codes in the header. There are examples when 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.