Programming & IT Tricks . Theme images by MichaelJay. Powered by Blogger.

Copyright

Facebook

Post Top Ad

Search This Blog

Post Top Ad

Responsive Ads Here

Archive

Post Top Ad

Contact


Editors Picks

Follow us

Post Top Ad

Fashion

Music

News

Sports

Food

Technology

Featured

Videos

Fashion

Technology

Fashion

Label

Translate

About

Translate

Sponsor

test

Weekly

Comments

Recent

Connect With us

Over 600,000+ Readers Get fresh content from FastBlog

About

Showing posts with label Web Performance. Show all posts
Showing posts with label Web Performance. Show all posts

Sunday, February 4, 2018

Unlocking Web Audio — the smarter way


The Web Audio API provides a powerful and versatile system for controlling audio on the Web, allowing developers to choose audio sources, add effects to audio, create audio visualizations, apply spatial effects (such as panning) and much more.
It can be used for developing sophisticated web-based games or interactive applications which include the capabilities of modern game audio engines as well as some of the mixing, processing, and filtering tasks found in modern desktop audio production applications; and it can be a very good complement to the more advanced graphics features offered by WebGL.
All this sounds awesome (pun intended), although, on iOS devices there is a slight caveat: the Web Audio API requires sounds to be triggered from an explicit user action, such as a tap, before any sound can be played on a web page.
The reason why iOS devices impose this user-gesture restriction is because they want to preserve a pleasant user experience by preventing ads or videos from playing sounds before user actually interacts with the content, and also to save battery life since playing audio does require additional processing power.
Within Web Audio API everything happens inside of an AudioContext, an audio-processing graph built from audio nodes linked together, which controls both the creation of the nodes it contains and the execution of the audio processing, or decoding.
On iOS devices this context is initially suspended (“locked”) and in order to enable sounds on a web page we need to get it out of the suspended state, or “unlock” it, within first user interaction.
Earlier solution to this issue proposed creating an empty sound on the fly and playing it back once user interacts with the page.
The reason why this approach works is because playing an audio source within a locked audio context sets it into running state before actually playing the audio.
Let’s start putting some code together in order to try and come up with a simpler solution. First we need to instantiate an audio context to be able to do any audio manipulation:
Then right after we create an audio context we should check its state property.
If the state is equal to suspended we might be dealing with an iOS device:
Some desktop browsers like Firefox Quantum leave an audio context in suspended state right after instantiating it, so in order to make sure we are really dealing with an iOS device we need to check if touch events are available as well:
If the audio context is suspended we can call its resume() method to set it into running state:
Now, you might be thinking “well, it can’t be this simple…”

…and you are right 😔. This code needs to be run within a user interaction in order to actually work. So we are going to wrap it up in a function and add that function as a touch event listener.
In order to try and unlock audio context as soon as possible we will run our code on the first touchstart event that occurs anywhere on the page:
One issue with this approach is that with some iOS versions trying to unlock Web Audio on touchstart event doesn’t work.
touchstart could be the beginning of a scroll gesture, and playing audio during this gesture could be completely undesirable from a user's perspective.
So to take this into account we also need to try to unlock Web Audio from within touchend event as well as on the initial touchstart event:
Once the audio context has been unlocked we would want to remove touch event listeners since we don’t need them anymore. For this we need to figure out when the audio context was actually unlocked.
Technique used in an earlier solution to determine this was to query the playbackState attribute of the sound, that was created on the fly, shortly after starting its playback. Doing it directly after wouldn’t work since starting a sound is an asynchronous action so querying had to be done from a timeout callback.
Then, if the sound was in PLAYING_STATE or FINISHED_STATE, you could assume that the context was unlocked.
This approach might still work in some cases but it is far from simple and introduces a compatibility issue since playbackState is no longer supported by the official Web Audio API specification.
One neat thing is that resume method of the audio context actually returns a Promise object. When that promise resolves we are certain that audio context has been unlocked and that we can remove touch event listeners:
And there you go: a bulletproof way of unlocking Web Audio on iOS devices!
Let’s make a few more adjustments to make this piece of code reusable. First let’s wrap it all in a function and put it in a try...catch block in order to prevent any unexpected errors from breaking our entire app:
And finally let’s provide some useful info like if there was an actual need to unlock Web Audio or if an error occurred and what was the reason for it. We can do this by wrapping everything inside of a Promise and returning it from our function:
Now you can use this function anywhere in your code like this:

Friday, January 19, 2018

Are there any unavoidable technologies?


Last night I was struggling to fall asleep. So I started to reflect on a documentary I had seen. It was dedicated to Nikola Tesla, the visionary inventor who was obsessed with electrical energy at the turn of the 19th and 20th centuries.
The story that made me reflect is the famous “currents war” (a movie version with Benedict Cumberbatch has just been released). Thomas Alva Edison argued that direct current was the ideal solution to “electrify” the world, and invested on it large sums. Tesla, who worked a few months for Edison, was instead convinced that alternating current was to be used.
I do not go into technical explanations. Let’s just say that Tesla, allying with Edison’s rival, the industrialist George Westinghouse, won it. Today we use alternating current (AC), but then transform it into continuous (DC) when we need to power our digital devices (or any other battery-powered object).
The question I asked myself was: if there were no Westinghouse and Tesla, would we have direct current distribution networks today?
Most likely not, because the advantages of AC distribution would still have emerged, and even rather soon.
More generally, the question is: are there unavoidable technologies?
Are there any alternative technological paths?
In the only case study available, that of human civilization, some discoveries and inventions, and the order with which they were made, seems to be obligatory: fire-> metals-> agriculture-> city-> wheel-> earthenware for example.
But also hunter-gatherer societies could have invented the wheel: it would have been very convenient for them, there was no reason not to have the idea and they had the ability to build it. Perhaps some tribes did so, using it for generations before memory was lost.
A sculpture of Göbekli Tepe -By Teomancimit — Yükləyənin öz işi, CC BY-SA 3.0
Scholars think that to get to the monumental buildings, cities and civilizations we must go through the agriculture: the production surplus is able to support a large number of people and to give birth to social classes, as nobles and priests dispensed from manual work but able to “commission” great works.
The extraordinary discovery of the Göbekli Tepe temple — dating from around 9,500 BC — has however questioned the need for the transition to an urban society with social differentiations to create such buildings.
Another example. Sophisticated mechanisms such as those of clocks began to spread in the early Middle Ages, with the first specimens placed in church bell towers.
Why did not the Greeks or the Romans, so skilled in the practical arts, come to develop similar mechanisms? In fact, after the discovery of the Antikythera mechanism, a sophisticated astronomical calculator, we have seen how the capabilities (for example to have minimum tolerances) and the techniques to build high precision instruments existed. Probably social, economic and commercial structures more than technological limits did not allow to have Roman pendulum clocks. In the same way, having a lot of low-cost labor, the slaves, did not stimulate the invention of steam engines, if not some rare and simple system used for “special effects” in the temples.
A reconstruction Antikythera mechanism- Dave L via Flickr CC BY 2.0
With regard to the innovations of the last 120 years, it is important to underline, alas, the crucial importance of the two world wars, especially the second, for the acceleration of technological development; we only think of rocketry and computer science, born in that period, and electronics developed shortly after (and there was the Cold War …).
If there had not been World War II, what technologies would be surrounded by our daily life?
Probably we will be at the level of the 60s / 70s, with mainframes, first satellites in orbit, color televisions but with cathode ray tubes, first commercial jet planes, just in time production chains etc.
Perhaps an analog Internet would have developed, thanks to unpredictable developments in the amateur radio network hybridized to systems such as fax and video / audio cassettes.
Difficult to establish the timelines, life cycles of individual technologies, their interconnections and interdependencies.
In a complex system such as that of human society, small variations in the initial conditions can generate great changes in the trajectories and directions of the space of innovations.
As a last example we think of the web. Sir Timothy John Berners-Lee created it while working at CERN in 1990.
The web (or a similar one) could have been developed at least 10 years before, in one of the American universities already inter-connected with a telematic network.
This would have meant that the portals of the first web would have appeared at the end of the 80s, the web 2.0 around 1994, the social networks would have been established around 1997 and today … we can not know it. Also because there would have been a longer interval to have the mobile web, since in any case the evolution of mobile telephony would have followed its course as in our timeline. Or not?

This story is published in The Startup,

Tuesday, January 16, 2018

9 Effective Tips on Visual Hierarchy


Sufficient visual hierarchy is a foundation of a successful digital product. It helps to organize UI elements in an effective way so that content would be easy to comprehend and pleasant to see. The presentation of visual elements has a great impact on user experience. If the components are organized wisely, users navigate and interact with a product without efforts and enjoy the process.
So, what makes powerful visual hierarchy? Of course, different kinds of products require different methods of building it still there are some common solutions helpful for UI content organization. Today’s article provides useful tips on creating the compelling visual hierarchy for web and mobile products.

Keep business goals in mind

There are often business goals standing behind a digital product. To achieve them, creative team needs to work out which UI elements are more important and prioritize them according to their roles. For example, all the elements on e-commerce websites perform the tasks of various levels. The item images are usually the main eye-catchers since they have to encourage customers to consider it. A heading goes after the image explaining what it is and the next important stage is a CTA button calling people to buy an item. By considering business and marketing goals set for the website or app, the creative team can effectively prioritize visual content and make a product stand out the crowd.
Design Agency Landing Page

Consider scanning patterns

In our previous articles, we mentioned that before reading a web page people scan it to get a sense of whether they are interested. Different studies, including the ones by Nielsen Norman Group, have revealed several popular scanning patterns among which “F” and “Z”-shaped.
F-pattern appears mainly on digital pages or screens with the big amount of content such as blogs, news platforms etc. Users’ eyes move in F-shape: first, they scan a horizontal line on the top of the screen, then move down the page a bit and read across the shorter horizontal line, finishing with the vertical line down on the left side of the copy where people look for keywords in the paragraphs’ initial sentences.
Z-shaped pattern takes place on the pages which are not so heavily concentrated on copy or those which don’t require scrolling down. The pattern is the following: people first scan across the head of the page starting from the top left corner, searching for core information, and then go down to the opposite corner at a diagonal, finishing with the horizontal line at the bottom of the page from its left to right.
Knowing these patterns designers organize content putting all the core UI elements on the most scanned spots to draw users’ attention.

Functionality first

The visual hierarchy may seem to be oriented only to the aesthetic aspects but it’s not like that. First of all, by structuring and organizing visual elements designers need to make sure a product is clear to use and the navigation works right. The visual hierarchy which is built exceptionally on aesthetics can’t work effectively. User interface with the badly structured content leads to the bad UX. So, while building visual hierarchy designers need to consider functions of UI elements and a role they play in the navigation process.
Seafood Recipes Landing Page

White space is a visual element

White space, or negative space, is not just an area between design elements, it is actually a core component of each visual composition. It is a tool able to make all the user interface elements noticeable to users’ eyes. Designers can group or separate UI components so that they could create the effective layout. Moreover, negative space helps to emphasize particular elements which require deep attention from users. White space is an effective instrument for creating visual hierarchy so designers need to work on its balanced usage.
Colony Landing Page

Apply the golden ratio

We devoted one of our latest articles to the golden ratio applied in design. It is a mathematical proportion of the elements of different sizes which is thought to be the most aesthetically pleasing for human eyes. The proportion equals 1:1.618 and it is often illustrated with seashell-shaped spirals which many of you could have probably seen.
Designers often apply golden ratio at the stage of wireframing. It helps to plan a structure for the layout placing and sizing user interface elements in the right proportion which will be pleasant for users.
Tracking Widget

Use a grid

A grid is one of the key tools applied at the different stages of the creative process and visual hierarchy is not an exception. A grid helps to structure all the components and put them into the appropriate sizes and proportion. What’s more, designers can effectively work with the negative space since a grid shows if the elements are placed proportionally and even.

Add some colors

Color choice and combinations are essential for visual hierarchy as they help users to distinguish the core elements. The thing is that colors have their own hierarchy which is defined by the power of influence on users’ mind. There are bold colors such as red and orange as well as the weak ones like white and cream. Bold colors are easy to notice so designers often use them as the means of highlighting or setting contrast.
Moreover, applying one color to the several elements you can show that they are somehow connected. For example, you can choose a red color for purchase buttons so that people could intuitively find them when they need.
Financial Service Website

Pay attention to the fonts

Visual hierarchy includes a core subsection called typographic hierarchy which aims at modifying and combining fonts to build the contrast between the most meaningful and prominent copy elements which should be noticed first and ordinary text information. The fonts can be transformed by regulating sizes, colors, and families as well as their alignment. Different fonts can divide copy content into different levels so that users could perceive the information gradually. However, designers are recommended to keep the number of fonts within three since too many fonts look messy and make the design inconsistent.

Three levels for web, two for mobile

As we mentioned above, different fonts form typographic levels which consist of such elements as headlines, subheaders, body copy, call-to-action elements, and captions. There are three typographic levels: primary, secondary, and tertiary. The first one includes the biggest type and aims at drawing people’s attention to the core information on the screen. The next level provides copy elements which are easily scanned and help users navigate through the content. The tertiary level usually applies body text and some additional data which is presented via relatively small type.
In many cases, web products include all three levels since they are more likely to provide the big amount of content. On the other hand, designers are recommended to keep the number of layers within two while creating typography for mobile. The small screens don’t provide enough space for three levels so the elements of a secondary level such as subheaders have to step aside to make mobile UI look clean.
WineYard App
Effective visual hierarchy is not only about aesthetics. It aims at providing problem-solving navigation and interaction systems as well as friendly user experience. To create a sufficient visual hierarchy, designers need to organize all UI elements considering the functionality and business goals.

Saturday, January 13, 2018

JavaScript — Null vs. Undefined


Learn the differences and similarities between null and undefined in JavaScript

At first glance, null and undefined may seem the same, but they are far from it. This article will explore the differences and similarities between null and undefined in JavaScript.

What is null?

There are two features of null you should understand:
  • null is an empty or non-existent value.
  • null must be assigned.
Here’s an example. We assign the value of null to a:
let a = null;
console.log(a);
// null

What is undefined?

Undefined most typically means a variable has been declared, but not defined. For example:
let b;
console.log(b);
// undefined
You can also explicitly set a variable to equal undefined:
let c = undefined;
console.log(c);
// undefined
Finally, when looking up non-existent properties in an object, you will receive undefined:
var d = {};
console.log(d.fake);
// undefined

Similarities between null and undefined

In JavaScript there are only six falsy values. Both null and undefined are two of the six falsy values. Here’s a full list:
  • false
  • 0 (zero)
  • “” (empty string)
  • null
  • undefined
  • NaN (Not A Number)
Any other value in JavaScript is considered truthy.
If you’re not familiar with truthy/falsy values in JavaScript, I recommend reading my previous article: JavaScript — Double Equals vs. Triple Equals
Also in JavaScript, there are six primitive values. Both null and undefined are primitive values. Here is a full list:
  • Boolean
  • Null
  • Undefined
  • Number
  • String
  • Symbol
All other values in JavaScript are objects (objects, functions, arrays, etc.).
Interestingly enough, when using typeof to test null, it returns object:
let a = null;
let b;
console.log(typeof a);
// object
console.log(typeof b);
// undefined
This has occurred since the beginning of JavaScript and is generally regarded as a mistake in the original JavaScript implementation.
If you’re not familiar with data types in JavaScript, I recommend reading my previous article: JavaScript Data Types Explained

null !== undefined

As you can see so far, null and undefined are different, but share some similarities. Thus, it makes sense that null does not strictly equal undefined.
null !== undefined 
But, and this may surprise you, null loosely equals undefined.
null == undefined
The explanation as to why this is true is a little complex, so bear with me. In JavaScript, a double equals tests for loose equality and preforms type coercion. This means we compare two values after converting them to a common type. Since both null and undefined are falsy values, when we compare them with loose equality, they are coerced to false prior to comparison.

Practical Differences

All of this is great, but what about a practical difference between null and undefined?
Consider the following code snippet:
let logHi = (str = 'hi') => {
  console.log(str);
}
The code above creates a function named logHi. This function requires one parameter and sets the default of that parameter to hi if it isn’t supplied. Here’s what that looks like:
logHi();
// hi
We can also supply a parameter to overwrite this default:
logHi('bye');
// bye
With default parameters, undefined will use the default while null does not.
logHi(undefined);
// hi
logHi(null);
// null
Thanks to Tim Branyen for the code inspiration.

Summary

  • null is an assigned value. It means nothing.
  • undefined typically means a variable has been declared but not defined yet.
  • null and undefined are falsy values.
  • null and undefined are both primitives. However an error shows that typeof null = object.
  • null !== undefined but null == undefined.

Sunday, January 7, 2018

All you need to know about Progressive Web App


The officially unofficial PWA logo
By now you must have heard this buzz word called “ Progressive Web App ”. Let me give you a simple definition about PWAs.
Progressive Web Apps are Web Apps which combines the best features of Web and Native Apps. It is progressive because it is constantly progressing.

Why Progressive Web Apps?

Now let’s talk about the “WHY”. Why Frances Berriman and Alex Russell came up with a concept called Progressive Web Apps? Before that let’s understand what problems does it solve.

Problems with Native Apps?

We all have used Android or iOS apps on our smartphones. We use them for all kinds of thing. But while installing any Android/iOS apps we go through these problems :
  1. Is this app worth downloading?
  2. Do I have enough space?
  3. My available data is not sufficient.
One recent survey shows that people are turning away from Android/iOS apps, because not all app experiences are satisfying or worthwhile. Some people simply don’t want any more apps on their phone, some even hesitate to download any app.
If you take a look at the apps installed on your mobile right now there might be at least a dozen apps that you do not use regularly. Sometimes apps only works good when the phone has an active internet connection.
The irony is that most of the apps have a fully responsive website performing the same functions. So why waste your precious disk space and your internet data on your smartphone by installing the native app? The average size of apps that we install from play store/app stores would range from 30–200MB. Moreover, these app needs to updated every week! But Progressive Web Apps are within some KBs and are automatically updated. Thanks to service worker. 🙂
What if a website can do that and much more than a Native app? This is what Progressive Web Apps (PWA) are trying to accomplish.
In short, Progressive web apps combine everything that is great about a native mobile application with everything that is great about a mobile website.
Some other ways I like to describe them:
“The best of the web, plus the best of native apps”
Or, in Alex’s words:
“Just websites that took all the right vitamins”

Features of PWAs:

  • Progressive — The word progressive means it works for every user, regardless of browser choice because they’re built with progressive enhancement as a core tenet.
  • Responsive — Automatically adjustable to any form: desktop, mobile, tablet etc.
  • Load Time — Progressive Web Apps are instantly available
  • App-like — Feels like a mobile app with app-style interactions since it’s built on the app shell model.
  • Fresh — Always up-to-date so you do not need to update it again and again like any other Android/iOS apps.
  • Safe — Served via HTTPS to ensure content is securely delivered
  • Engaging — Features like push notifications, etc. makes it very engaging.
  • Installable — Allows users to install the website as an app on their home screen without the taking user to an app store.
  • Linkable — Easily shared via a URL and do not require complex installation.

Benefits of making a Progressive Web App rather than building a fully functional Android App?

  • Cost Effective  — For an app publisher, the biggest advantage is the cost saving in terms of app development and maintenance. Because it is assumed that making a website is lot more easier than making a Android App.
  • Cross Platform— Unlike any other apps, Progressive Web Apps are not restricted to any specific platform. That means you do not need to develop separate versions of app for different platforms.

10 REASONS PROGRESSIVE WEB APPS WILL BE THE FUTURE OF APPS

Some Popular Companies that Do Progressive Web Apps

Introducing Flipkart Lite — The progressive mobile web app

Flipkart, India’s largest e-commerce site, decided to combine their web presence and native app into a Progressive Web Application that has resulted in a 70% increase in conversions. Flipkart’s PWA takes merely 100KB to download, is 100 times smaller than the 10MB Android app and 300 times smaller than the iOS app. Repeat visits take less than 10KB to download.

How to use a Progressive Web App?

Probably, you must be wondering how to use a Progressive Web App! Well, you can just click on any links mentioned above. But provided that you must be using a smart phone in order to install it your own device.
Now let’s click open Flipkart in chrome. ( You must be using a Mobile Device ). Below are some screenshots which demonstrates the installation of a PWA.

Chrome Dev Summit Announcments:

Progressive Web Apps: Great Experiences Everywhere (Google I/O ‘17)

Microsoft is supporting Google’s Progressive Web Apps platform and that’s great news for everyone.

Microsoft recently announced that Progressive Web Apps (PWA) will soon be supported by the Microsoft Edge web browser. Moreover, a few apps hitting the Windows Store — like Slack and Trello — are now mixing PWA with Electron and elements of the Universal Windows Platform (UWP).


Interested for our works and services?
Get more of our update !