Thursday, April 2, 2020

WhatsApp tests multi-device support, expiring messages on beta, updates iOS 13

WhatsApp is one of the best chatting apps to have on your phone. It’s easy to use and equipped with a number of handy features that make it one of the most popular messenger – globally. However, there are some limitations with WhatsApp that devalues it in front of other competing apps. One of...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Saima Salim via Digital Information World

Using ipdata for Geolocation

When most people think of geolocation, they remember the familiar pop-up notifications saying that the "website wants to know your location". But did you know that you can get geolocation information about your visitors with the IP address alone, without requiring any extra permissions?

To web developers, geolocation is a treasure trove of information and capabilities that can enhance the visitor’s experience and provide meaningful information to the developer. While the HTML5 Geolocation API can certainly provide developers with the actual GPS coordinates of the visitor’s device, developers more commonly need a broader set of location data. They can get that information using the visitor’s IP address.

By itself, an IP address is simply that: an address of a device on the internet. However, the World Wide Web is well over 20 years old, and over that large span of time, tons of data has been collected, correlated, and combined in relation to millions of IP addresses. While there are many third-party services that offer IP geolocation data, none are as accurate or reliable as ipdata. Before we look at how to use ipdata’s service, let’s first look at why you may want to use geolocation data.

Uses of Geolocation

There are many legitimate reasons why you would want to gather geolocational data on your visitors and use it in your applications.

For one, you can serve regional content based upon your visitor’s IP address. Does your website offer products globally but services locally? With IP geolocational data, you can serve your normal, product-based content and target local visitors with special content about your services.

Using geolocational data can also help you identify visitors that fall under the EU’s General Data Protection Regulation so that you can properly adhere to the GDPR for those visitors.

Why ipdata?

With ipdata, you can access an accurate IP address intelligence API, allowing you to look up the approximate location of any IP address. But on top of that, ipdata also provides aggregated open-source threat intelligence data and IP to company lookups, as well as internationalization data like currencies, time zones, and languages. Many organizations and companies—NASA, Comcast, and Disney, just to name a few—trust ipdata with the geolocational data they provide.

While you can use any HTTP client to connect to and use their RESTful API, ipdata provides open-source libraries for C#, Java, PHP, JavaScript, and Python to make working with the API and response data a breeze. Third-party libraries are available for Ruby, Swift, and Go.

Note: this article uses ipdata’s JavaScript library in a Node application, but the same ideas and concepts can be applied to other languages. Refer to the official ipdata library documentation.

Using ipdata's API

The first thing we need is a Node application; be sure to install the latest Node LTS version from the Node.js website. Create a new directory called tutsplus-ipdata for your application’s project. Then open your operating system’s terminal application, navigate to your newly created directory, and type the following to initialize the project:

We now need to choose our application framework. Yes, we don’t technically need one, but frameworks like Express and Hapi greatly increase our productivity when building Node-based web applications. We’ll use Hapi, so we need to install it, as well as the ipdata package, with the following command:

In a real application, you’d naturally want to install packages for handling static files, views, errors, and so on. Hapi and ipdata are the only packages we’ll need for this tutorial because our server will be extremely simple: it will only respond with text.

Writing the Server

If you’re new to Hapi, the process for creating and initializing the server is straightforward. First, create a new file called index.js and create the server with the following code:

The first line of this code imports the Hapi object, which we use to create our server by calling its server() method. The server() method accepts an object that allows us to configure our server. In the above code, we configure our server to run on the localhost and listen on port 3000.

Next, we set up our single route using the server’s route() method:

This route handles GET requests for the home, or root, of our application. The handler function executes, returning a simple string, when the server receives a request that matches this route.

Lastly, we start the server with the following code:

Because the server’s start() method is asynchronous, we can choose how we want to use it. This code uses the await keyword, which means we have to execute this code within a function marked as async. So we’ll wrap the server creation, configuration, and execution within an asynchronous function, like this:

This code creates a simple server that doesn’t do anything except output “Hello, Tuts+” when you view http://localhost:3000 in your browser. Test it for yourself by running node index.js in your terminal.

We can add some useful functionality to this simple test server by writing and registering a plugin that only allows requests from certain countries—a whitelist.

Using ipdata for a Whitelist

The geolocation data returned by ipdata’s API contains a host of information that we can use to create a whitelist (or blacklist, if you want to take the opposite approach). To name just a few: you can retrieve the city, region/state, country, continent, ISP, and hosting provider that are associated with an IP address. For our purposes, we'll whitelist requests coming from certain countries.

Create a new file called whitelist.js, and type these first two lines:

The first line of this code imports the IPData constructor function, which is used to create the ipdata API client. The second line creates the client, passing in the API key associated with your account. If you do not have an account, you can sign up for a free account from ipdata. You’ll receive your API key via email. You can use the string "test" for testing purposes, but be aware it is rate limited.

Now define the plugin with the following code:

This code demonstrates the boilerplate for a basic Hapi plugin. It exports the plugin object and defines the plugin’s name property and register() method.

Unlike Express, Hapi doesn’t use, or even have the concept of, middleware. Instead, you hook into lifecycle events to process incoming requests, and you do so using the server’s ext() method, as shown in the following code:

This code goes inside the plugin’s register() method, and it sets up an event handler for the onRequest lifecycle event. The asynchronous function provided to ext() will handle the event and allow you to process the request.

We’ll start the processing by defining our whitelist of countries, which is an array of string values that contain the country codes of our whitelisted countries. Then, we’ll retrieve the requester’s IP address and use it to query the ipdata API, as shown here:

Note that if this application is running on your machine, the requesting IP address is the loopback IP address for your machine, and there is no geolocational data associated with that IP address. Instead, the above code uses the IP address for the Envato Tuts+ website.

The ipdata client is simple to use—its lookup() method accepts a number of arguments, the most notable being the desired IP, and queries ipdata’s API with the provided information.

The response from lookup() is an object that contains a wide range of properties, depending upon the result of the query. For example, the response object always contains a property called status that indicates if the provided IP address exists within ipdata’s database. It is an HTTP status code, so it's a good idea to check its value before doing anything else.

The property we are concerned with is country_code, and we can use it to check our whitelist. The following code uses both the status and country_code properties:

If the query status is 200 and the country code exists in the whitelist, then we tell our server to continue processing the request with the next plugin or the handler for the route—essentially allowing the requester to access the resource they requested. Otherwise, we takeover the response with a 403 status.

As previously mentioned, the query result object contains a wide variety of properties, but we only need one: country_code. As such, we can increase network efficiency by telling the lookup() method that we only want a certain set of properties, like this:

This code now passes an array that contains only the properties that we need (the status property is always included, so we do not need to specify it in the array). With this change, the completed plugin looks like the following:

Regsitering the Plugin

Now we need to register our whitelist plugin. Before defining our routes in index.js, add the following line:

The complete server code is as follows:

If you haven’t already, kill the server running in your terminal with Control-C, and run node index.js again. If you used the Envato Tuts+ website’s IP, you should see the text "Hello, Tuts+" in the browser. If you used an IP address from a country not listed in the whitelist, or you used the IP address from the local machine, then you’ll see the text "You are not allowed".

Conclusion

For web developers, ipdata provides an invaluable service. Not only does it allow you a sense of who your visitors are, but it lets you incorporate region-specific content to create a meaningful experience for your visitors. It’s free to get started and easy to use, so give ipdata a try today!


by Jeremy McPeak via Envato Tuts+ Code

Keep it Real and Profound with Facebook Messenger’s New Auto-Status Feature

Jane Manchun Wong reported that Facebook is testing a new “Auto-Status” feature to be incorporated in its Messenger application. With this feature, you will be able to update your location, weather and some other indicators on automatic basis. With this kind of visual representation, you will be...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Arooj Ahmed via Digital Information World

Facebook Adds New 'Community Help' Tool Allowing Its Users To Request Or Offer Aid In Their Neighborhood

Facebook announced the addition of a new ‘Community Help’ tool in its efforts to provide assistance and relief during the coronavirus pandemic.How the new tool works for the users to offer and request aid within their community.Facebook might keep the new tool as a permanent option. Facebook has...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Arooj Ahmed via Digital Information World

Five Ways to Lazy Load Images for Better Website Performance

Five Ways to Lazy Load Images for Better Website Performance

With images being among the most popular type of content on the web, page load time on websites can easily become an issue.

Even when properly optimized, images can weigh quite a bit. This can have a negative impact on the time visitors have to wait before they can access content on your website. Chances are, they get impatient and navigate somewhere else, unless you come up with a solution to image loading that doesn’t interfere with the perception of speed.

In this article, you’ll learn about five approaches to lazy loading images that you can add to your web optimization toolkit to improve the user experience on your website.

What Is Lazy Loading?

Lazy loading images means loading images on websites asynchronously — that is, after the above-the-fold content is fully loaded, or even conditionally, only when they appear in the browser’s viewport. This means that if users don’t scroll all the way down, images placed at the bottom of the page won’t even be loaded.

A number of websites use this approach, but it’s especially noticeable on image-heavy sites. Try browsing your favorite online hunting ground for high-res photos, and you’ll soon realize how the website loads just a limited number of images. As you scroll down the page, you’ll see placeholder images quickly filling up with real images for preview. For instance, notice the loader on Unsplash.com: scrolling that portion of the page into view triggers the replacement of a placeholder with a full-res photo:

Lazy loading in action on Unsplash.com

Why Should You Care About Lazy Loading Images?

There are at least a couple of excellent reasons why you should consider lazy loading images for your website:

  • If your website uses JavaScript to display content or provide some kind of functionality to users, loading the DOM quickly becomes critical. It’s common for scripts to wait until the DOM has completely loaded before they start running. On a site with a significant number of images, lazy loading — or loading images asynchronously — could make the difference between users staying or leaving your website.
  • Since most lazy loading solutions work by loading images only if the user has scrolled to the location where images would be visible inside the viewport, those images will never be loaded if users never get to that point. This means considerable savings in bandwidth, for which most users, especially those accessing the Web on mobile devices and slow-connections, will be thanking you.

Well, lazy loading images helps with website performance, but what’s the best way to go about it?

There’s no perfect way.

If you live and breathe JavaScript, implementing your own lazy loading solution shouldn’t be an issue. Nothing gives you more control than coding something yourself.

Alternatively, you can browse the Web for viable approaches and start experimenting with them. I did just that and came across these five interesting techniques.

#1 Native Lazy Loading

Native lazy loading of images and iframes is super cool. Nothing could be more straightforward than the markup below:

<img src="myimage.jpg" loading="lazy" alt="..." />
<iframe src="content.html" loading="lazy"></iframe>

As you can see, no JavaScript, no dynamic swapping of the src attribute's value, just plain old HTML.

The loading attribute gives us the option to delay off-screen images and iframes until users scroll to their location on the page. loading can take any of these three values:

  • lazy: works great for lazy loading
  • eager: instructs the browser to load the specified content right away
  • auto: leaves the option to lazy load or not to lazy load up to the browser.

This method has no rivals: it has zero overhead, it's clean and simple. However, although at the time of writing most major browsers have good support for the loading attribute, not all browsers are on board yet.

For an in-depth article on this awesome feature for lazy-loading images, including browser support workarounds, don't miss Addy Osmani's “Native image lazy-loading for the web!”.

#2 Lazy Loading Using the Intersection Observer API

The Intersection Observer API is a modern interface that you can leverage for lazy loading images and other content.

Here’s how MDN introduces this API:

The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document’s viewport.

In other words, what’s being asynchronously watched is the intersection of one element with another.

Denys Mishunov has a great tutorial both on the Intersection Observer and on lazy loading images using it. Here’s what his solution looks like.

Let’s say you’d like to lazy load an image gallery. The markup for each image would look like this:

<img data-src="image.jpg" alt="test image">

Notice how the path to the image is contained inside a data-src attribute, not a src attribute. The reason is that using src means the image would load right away, which is not what you want.

In the CSS, you give each image a min-height value, let’s say 100px. This gives each image placeholder (the img element without the src attribute) a vertical dimension:

img {
  min-height: 100px;
  /* more styles here */
}

In the JavaScript document, you then create a config object and register it with an intersectionObserver instance:

// create config object: rootMargin and threshold
// are two properties exposed by the interface
const config = {
  rootMargin: '0px 0px 50px 0px',
  threshold: 0
};

// register the config object with an instance
// of intersectionObserver
let observer = new intersectionObserver(function(entries, self) {
  // iterate over each entry
  entries.forEach(entry => {
    // process just the images that are intersecting.
    // isIntersecting is a property exposed by the interface
    if(entry.isIntersecting) {
      // custom function that copies the path to the img
      // from data-src to src
      preloadImage(entry.target);
      // the image is now in place, stop watching
      self.unobserve(entry.target);
    }
  });
}, config);

Finally, you iterate over all of your images and add them to this iterationObserver instance:

const imgs = document.querySelectorAll('[data-src]');
imgs.forEach(img => {
  observer.observe(img);
});

The merits of this solution: it’s a breeze to implement, it’s effective, and has the intersectionObserver do the heavy-lifting in terms of calculations.

On the flip side, although the Intersection Observer API is supported by most browsers in their latest versions, it’s not consistently supported by all of them. Fortunately, a polyfill is available.

You can learn more on the Intersection Observer API and the details of this implementation in Denys’s article.

#3 Lozad.js

A quick and easy alternative for implementing lazy loading of images is to let a JS library do most of the job for you.

Lozad is a highly performant, light and configurable lazy loader in pure JavaScript with no dependencies. You can use it to lazy load images, videos, iframes and more, and it uses the Intersection Observer API.

You can include Lozad with npm/Yarn and import it using your module bundler of choice:

npm install --save lozad

yarn add lozad
import lozad from 'lozad';

Alternatively, you can simply download the library using a CDN and add it to the bottom of the HTML page in a < script> tag:

<script src="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"></script>

Next, for a basic implementation, add the class lozad to the asset in your markup:

<img class="lozad" data-src="img.jpg">

Finally, instantiate Lozad in your JS document:

const observer = lozad();
observer.observe();

You’ll find all the details of how you can use the library on the Lozad GitHub repository.

If you don’t want to dive into the workings of the Intersection Observer API or you’re simply looking for a fast implementation that applies to a variety of content types, Lozad is a great choice.

Only, be mindful of browser support and eventually integrate this library with a polyfill for the Intersection Observer API.

The post Five Ways to Lazy Load Images for Better Website Performance appeared first on SitePoint.


by Maria Antonietta Perna via SitePoint

Käthe Kollwitz Memorial

Käthe Kollwitz Memorial
Käthe Kollwitz, was a German artist who worked with painting, printmaking (including etching, lithography and woodcuts) and sculpture.
by via Awwwards - Sites of the day

Wednesday, April 1, 2020

Instagram Considers To Add Multi-Participant Feature To Instagram Live

People are using live streaming apps and video chat apps amid the coronavirus lockdowns more than ever.Instagram is looking to create an option to add more than one guest to its live-streaming feature.Instagram might add its live streaming-feature to the web.Adding an option to host more than one...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Arooj Ahmed via Digital Information World