Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Articles Tagged ‘javascript’

Speed up your website – Part 4: JavaScript

Saturday, July 14th, 2018 by Servage
This is the fourth part of a simplified explanation of the "Yahoo best practices for speeding up your web site". Read the third part here. The third part is about CSS related optimization. Preferably place scripts at the bottom Scripts block parallel downloads of multiple items in the browser. Therefore you might want to place the scripts at the bottom of the page, if possible. It is a problem if your scripts alter the content of your document on the initial load, since you might want those scripts at the top. Make JavaScript (and CSS) external Including JavaScript and CSS in the HTML document reduces the amount of requests, but also ...

PHP-like in_array function in JavaScript

Monday, April 30th, 2018 by Servage
Recently I once more found myself in a situation where I really felt that I am a PHP-developer, more that a JavaScript-developer. Do you also find your self writing stuff like in_array() in JavaScript code? It happens often to me, that I take for granted in other languages, what I know and love in PHP. It also often takes quite a while to find a good alternative for missing functions in JavaScript, since Google often provides you with multiple options. One of the common functins I miss in JavaScript from PHP is in fact the "in_array"-function. Luckily there is a splendid JavaScript snippet here: function in_array (needle, haystack, argStrict) { ...

HTTP requests with the new Angular 4 HTTP Client

Tuesday, November 7th, 2017 by Servage
angular-4Angular 4.3 comes with a new way of sending HTTP requests: the HttpClient class. The older Http class can still be used and it is not deprecated, at least for now. However, HttpClient brings some new features and will likely replace the old class in the future. Let’s go through some of the features the new HttpClient has to offer. Modifying Requests with Interceptors One of the handy new features is the ability to intercept HTTP requests with interceptors. Intercepting a request means modifying it on the fly. One common use case for interceptors is to attach a session token to every request automatically to easily authenticate with an API. Interceptors are classes that ...

How JavaScript Promises Work

Sunday, October 15th, 2017 by Servage
javascript-codeA promise is an object that represents an asynchronous action that is yet to be completed. Consider an HTTP request that loads the details of a user account. If the request is sent inside a promise, your application can continue to work on other tasks while the HTTP request is sent. When it completes, a function is called where you can handle the data that was returned. Let’s have a closer look at promises and what makes them so powerful. Creating a Promise A new promise can be created with the new keyword using the Promise class. Promises are created inside a function that performs asynchronous tasks. Therefore, you could have the following ...

Building a Front End with Ember.js

Sunday, October 8th, 2017 by Servage
emberEmber.js is yet another JavaScript framework for building the UI for web applications. While there seems to be many JavaScript frameworks out there at the moment, each of them is targeted for a specific use case, or at least is more suitable for something than the others. Usually a single framework is not always the best choice for all kinds of websites and web applications. Let’s explore Ember together and figure out how it works and what types of websites benefit from it the most. Ember.js Quick Start If you have ever worked with Angular, chances are you find getting started with Ember quite easy. The process of setting up your first Ember ...

Angular 4 Best Practices

Monday, October 2nd, 2017 by Servage
angularAngular is one of the most popular front-end frameworks. Developers sometimes prefer to use their own approach when it comes to naming conventions, whitespace usage, file structure and so on. However, if every developer chooses their own path to follow, managing a single code base in a team becomes quite challenging. To solve this, Angular has a set of rules that all developers should follow when working on an Angular project. Let’s have a look at those recommendations set by the team behind Angular. File Names Let’s start with file and directory naming conventions. By following the Angular naming conventions, you can easily identify what a file does just by looking at the ...

What is Vue.js?

Tuesday, August 1st, 2017 by Servage
vueVue.js is a framework for building interactive user interfaces. It has gained quite a bit of popularity among front-end developers for being easy to use and working well in different types of projects. What is Vue.js more specifically and how does it work? Let’s find out. Vue for Views As the name might suggest, Vue.js is the V in MVC. You can use it to build the view side of your application without worrying about the rest of your technology stack because Vue.js works well with almost any type of back end. Vue utilizes the same approach with a virtual DOM as React, making it fast to render changes on a page. It is ...

Enhanced JavaScript with TypeScript

Tuesday, April 25th, 2017 by Servage
typescriptTypeScript is a relatively new programming language from Microsoft. It is a superset of JavaScript and adds some useful features to make JavaScript coding easier and less prone to errors. What does that mean and what are these useful features? Let’s find out! Static Type Checking As the name suggests, TypeScript introduces type checking. In practise this means that variables can now have a type. In typical JavaScript, all variables are created with the var keyword in ES5 and with let in ES6. The variables are automatically assigned the correct type based on what value the variable holds. This makes JavaScript a dynamically typed language. However, TypeScript is a statically typed language since ...

Modernized strings in ES6 JavaScript

Friday, April 14th, 2017 by Servage
ES6ECMAScript 6 (ES6) has brought a lot of great features to JavaScript over the years and continues to do so as the specification is being developed. One of the new features is called template strings, which is often used in for example modern Angular or React development. It allows developers to use strings in more advanced and easier ways. This includes a new way to use multi-line strings, using strings inside variables and more with a cleaner syntax. Multi-line Strings You have likely used the concatenation operator (+) or a backslash (\) to make multi-line strings in the past. While this works fine, the syntax is is not very clean and makes the ...

Scroll-based animations with WOW.js

Wednesday, March 29th, 2017 by Servage
wowjsMany websites have animations that trigger when you scroll enough to make the element visible. Today we will see how this works and how you can implement similar animations on your own website using an easy-to-use WOW.js JavaScript library together with ready-made animations from Animate.css. Getting the Required Files Since we are going to use both WOW.js and Animate.css libraries, we have to download and include them in an HTML file. Let’s start with downloading Animate.css, but first a quick introduction to the library. As the name suggests, Animate.css is an animation library built with only CSS. It allows you to animate elements using fading, sliding and many other types of animations. You ...