Wednesday, January 17, 2018

How to Optimize CSS and JS for Faster Sites

This article was sponsored by Aussie Hosting. Thank you for supporting the partners who make SitePoint possible.

User experience is the most important factor when it comes to the success of your online venture.

It doesn't matter if you run a niche blog, SaaS site, or an online store. If you somehow manage to botch up your audience's experience, don't expect to convert any of them into paying customers.

The good news is, any brand can methodically improve user experience by narrowing down on specific on-page factors.

Loading speed, for instance, is something that most website owners easily overlook.

According to conversion rate data, increasing your Internet site speed from eight seconds to two seconds may lead to a 74 percent increase in conversion rate.

That means that a slow site could cost you nearly half of your potential customers.

Seeing the Full Picture with PageSpeed Insights

To determine issues on your website that affect loading speed, you can use Google PageSpeed Insights. It's a free tool that automatically scans both the desktop and mobile versions of your site.

PageSpeed Insights

In addition to the issues detected, PageSpeed Insights will also show you a handful of actionable recommendations.

For site owners who never gave any thought to page loading speed, you may encounter the following issues:

PageSpeed Insights

These indicate that your CSS and JavaScript code is slowing your site down. And while it might sound like a job for full-fledged web developers, they're fairly easy to optimize with the help of tools.

Without further ado, here are the steps you need to take to minify your CSS and JavaScript assets.

Determine the Code to be Minified

Code minification is the practice of deleting characters that don't serve any function other than improving readability.

For example, inline comments may help developers comprehend what a particular section of code does. While it's useful for reviewing or debugging, they may also bloat the size of the code.

Minification removes these excess characters — therefore reduces bandwidth usage and boosts page loading speed.

Using PageSpeed Insights, you can easily identify which code requires minification. Simply click "Show how to fix" and follow the path in your CMS (Content Management System) or FTP (File Transfer Protocol) client.

Code minification

For example, if your website runs on WordPress, then all of your code should be consolidated in the "Editor" section. This can be found by under the "Appearance" tab from the primary dashboard.

Code minification

Optimizing Your Codes

Now that you've found the code in question, it's time to learn how to minify them.

Perhaps the easiest way to minify your code is to leverage automated tools. When it comes to CSS and JavaScript, some of the best tools for the job are CSS Minifier and JSCompress.

Using CSS Minifier

CSS Minifier is a free and simple tool that automatically compresses CSS assets. All you need to do is paste the code into the input field, set a compression level, and click "Minify."

CSS Minifier

Depending on the size of your code, it may take a few seconds to a minute to minify your code. Your new code can then be copied back into your CMS or FTP client interface.

Important: As a precaution, don't forget to create backups before making any changes in your site's code. Creating offline or cloud-based copies is a straightforward way to do this.

CSS Minifier

To test if your minification worked, go ahead and run another analysis on PageSpeed Insights. The CSS file you recently compressed should no longer appear under the "Minify CSS" details.

CSS Minifier

Using Asynchronous Loading on JavaScript

Compared to CSS, JavaScript is slightly trickier to minify correctly. Before you run your code through JSCompress, consider implementing asynchronous code loading first.

Also referred to as "Lazy Loading" — but in the context of JavaScript, asynchronous loading works by dynamically loading functions.

To use asynchronous loading, just add the "async" tag when calling the .js file. This can be done in your website's HTML source code.

Here's an example on how to do this:

<script src=”yourscript.js” async> </script>

You can refer to this post for more information on how this works and its usage. If you're completely new to HTML, read this beginner's guide until you're comfortable with the basics.

Combining JavaScript Files

Another point worth mentioning when it comes to optimizing JavaScript is to combine files in a single page. Doing so will reduce the number of HTTP requests that the browser makes, which would invariably speed up loading time.

For example, rather than calling multiple .js files in your source code:

Continue reading %How to Optimize CSS and JS for Faster Sites%


by Gary Stevens via SitePoint

#190: Small Tweaks To Make a Huge Impact on Your Site's Accessibility

Mobile Dev Weekly January 17, 2018   #190
Chris Brandrick recommends
Announcing the Ionic PWA Toolkit Beta — "The recommended way to easily build fast and production-ready PWAs with Ionic.""
Justin Willis
Holly Schinsky recommends
Small Tweaks To Make a Huge Impact on Your Site's Accessibility — Looking to address your website’s accessibility? Here, Andy Bell shares some tips on “small things that can make a big difference, while hopefully not affecting your development process too much”.
CSS Tricks
Sponsored
Seamless Continuous Integration and Delivery for Mobile Pros — With Nevercode you can build, test and deploy iOS, Android, React Native, Ionic and Cordova apps. Set up your projects in minutes, let Nevercode take care of server maintenance and spend your time on more enjoyable things. Like writing quality code.
Nevercode.io

Holly Schinsky recommends
Your Guide to Getting Feedback Fast and Building Better Apps — Get feedback from your apps fast by including feature flags, metrics and more.
Marco Kuiper
Brian Rinaldi recommends
The State of UX for 2018 — A look at UX design and development trends, most of which are related to mobile app design.
Anthony Miller
Chris Brandrick recommends
Jasonette Agent — A new architecture for building native apps that utilizes JavaScript technologies without sacrificing native peformance/user experience.
Jasonette
Mobile Web
Brian Rinaldi recommends
How to Debug Progressive Web Apps using Browser Developer Tools — This tutorial explains what tools the Chrome and Firefox Dev Tools display that help you debug a Progressive Web App.
Write Software
Chris Brandrick recommends
Typography for Glanceable Reading: Bigger Is Better — 40% of the phone sessions last less than 15 seconds, so large glanceable typography can be important.
Nielsen Norman Group
Peter Cooper recommends
Leaflet 1.3.0: A JavaScript Library for Mobile-Friendly Interactive Maps
Andrew Cherniavskii
Hybrid Apps
Holly Schinsky recommends
Hosting an Ionic PWA with Firebase Hosting — Part three in a series on building a Progressive Web App with Ionic, focused on hosting the app with Firebase. Here are part one and part two.
Josh Morony
Holly Schinsky recommends
Uploading Files from an Ionic App to Firebase Cloud Storage — Learn how to add File Upload to Firebase Cloud Storage capabilities to your Ionic apps with this short video.
Samarth Agarwal
Native Development
Chris Brandrick recommends
Kotlin 1.2.20 Is Out — A new bugfix and tooling update for Kotlin 1.2.
Dmitry Jemerov
Chris Brandrick recommends
Announcing Realm Cloud: Realm Platform as a Service Beta — A new ‘as-a-service’ version of the Realm Platform — described as “the easiest way to add offline first and realtime data sync features” to your mobile apps.
Realm
Brian Rinaldi recommends
Getting Started with Augmented Reality in NativeScript — How you can build your first AR iOS app using NativeScript.
TJ VanToll
Chris Brandrick recommends
Best Practices for Mobile AR Design “AR is new, so creators need to think carefully when it comes to designing intuitive user interactions.”
Alesha Unpingco
Holly Schinsky recommends
Building A News App With Flutter and Firebase
Ankur Kedia
Chris Brandrick recommends
How We Improved Our Android App "Cold Start" Time by 28%
Anshu Rustagi
Chris Brandrick recommends
Reverse-Engineering the iPhone X Home Indicator Color — What color is the home indicator? The answer is surprisingly complex.
Nathan Gitter


by via Mobile Dev Weekly

HTML 5.2's new dialog element, an updated Speedometer benchmark and changes to Chrome's Autoplay policy

Frontend Focus
Issue 323 — January 17, 2018
A great introduction to the concepts around lengths, units, and content-based sizing with layouts based on Grid and Flexbox.
Rachel Andrew

An introduction to HTML’s new dialog element for adding native modal boxes.
Keith J. Grant

A well presented, visual guide to what different CSS properties do.
Jeremy Thomas

Get a Linode server up and running in seconds. Simply choose your plan, distro and location and you’re ready to deploy your server. Get $20 credit on a new account.
Linode Cloud Hosting   Sponsor

An update to a benchmark for modern web app responsiveness that simulates user interactions upon a basic app. 2.0 better reflects the frameworks, tools, and patterns in wide use today.
WebKit

Muted autoplay will be fine, but for audio to play some conditions must be met. Only in Chrome Canary for now, but if you use autoplaying videos you need to be prepared.
Google Developers

Works with GitHub Flavored Markdown (GFM) but can be extended with your own extensions. Supports all major browsers (IE10+). GitHub repo.
NHN Entertainment

Jobs

In Brief

Frontend Developer Love Conference 15-16 Feb Amsterdam ❤️ news
Frontend Developer Love  Sponsor

How To Make a Drag-and-Drop File Uploader With Vanilla JavaScript tutorial
Joseph Zimmerman

'display: contents' is Coming tutorial
Manuel Rego Casasnovas

Small Tweaks To Make a Huge Impact on Your Site's Accessibility tutorial
CSS Tricks

Decorative Letter Animations with anime.js and Charming tutorial
Some fun shape and letter animation experiments.
Mary Lou

Simplifying the Apple Watch Breathe App Animation with CSS Variables tutorial
This goes amazingly deep on the CSS.
Ana Tudor

Keeping Users Engaged Through Better Front End Performance tutorial
Pantheon  Sponsor

Recording Video and Audio in Browser using the Web Media API video
Tim Ermilov

Zigzag Image–Text Layouts Make Scanning Less Efficient opinion
Nielsen Norman Group

Building a Mind-Controlled HTML5 Video story
Alex Castillo

Hey Meta: Website Meta Tag Checker and Builder tools
A tool to quickly check and (re)build some of your meta tags.
Igor Å tumberger

CSS Cheat Sheet: A Quick Go-To Reference for CSS Goodness tools
Adam Marsden

Optimize Web App Performance with Datadog tools
Collect and alert on real-time metrics from your web applications and infrastructure. Start a free trial.
Datadog  Sponsor

canvas-area: Lightweight HTML Container Element for Canvas Elements code
Stefan Goessner

Crooked Style Sheets: How Pure CSS Can Track You on Web Pages code
It’s either a tutorial or a warning, depending on your inclination.
Jan Böhmer

webshot-factory: Web Screenshots at Scale Based on Headless Chrome code
Ashish Shubham

InfiniteGrid: Arrange Card Elements Infinitely on a Grid Layout code
GitHub repo.
NAVER

Instagram.css: A Set of Instagram-style Filters Created in Pure CSS code
Yan Zhu

CSS Background Patterns Found on CodePen code
Freebie Supply

KaTeX: Fast Math Typesetting for the Web code
Easy-to-use library for TeX math rendering on the web.
Khan Academy


by via Frontend Focus

Luke Beard

Minimal redesign of Luke Beard’s personal One Pager featuring a subtle 3D tilt-effect when you move your cursor.

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

Building Games With Python 3 and Pygame: Part 3

Overview

This is part three of a five-part series of tutorials about making games with Python 3 and Pygame. In part two, we covered the TextObject class used to render text on the screen, created the main window, and learned how to draw objects like bricks, the ball, and the paddle. 

In this part, we will dive into the heart of Breakout and learn how to handle events, meet the main Breakout class, and see how to move the different game objects.

Handling Events

In Breakout, there are three types of events: key press events, mouse events, and timer events. The main loop in the Game class takes care of the key press and mouse events and delivers them to subscribers (by calling a handler function). 

While the Game class is very generic and has no Breakout specific knowledge, the subscription itself and how to handle each event are very specific.

The Breakout Class

The Breakout class is where most of the domain knowledge about the Breakout game is managed. We will meet the Breakout class several times during this series. Here are the lines that register the various event handlers. 

Note that all key events for both the left and right arrow keys will go to the same handler method of the paddle.

Handling Key Presses

The Game class will call the registered handlers for each key event and pass the key. Note that it doesn't the Paddle class. In Breakout, the only object that is interested in these events is the paddle. When a key is pressed or released, its handle() method is called. 

The Paddle doesn't need to know if it was a key down or key up event because it manages the current state through a pair of boolean variables: moving_left and moving_right. If moving_left is True then it means the left arrow key is pressed and the next event will be key up, which will release it. The same goes for the right arrow key. The logic is as simple as toggling these variables in response to any event. 

Handling Mouse Events

Breakout has a game menu you'll meet soon. The button on the menu handles various mouse events such as movement and clicks (mouse down and mouse up events). In response to these events, the button updates an internal state variable. Here is the mouse handling code:

Note that the handle_mouse_event() method that is registered to receive mouse events checks the type of the event and forwards it to the specific method that handles that event type.

Handling Timer Events

Timer events are not processed through the main loop. However, since the main loop is called every frame, it's easy to check if a certain timed event is due. You will see an example of this later when discussing timed special effects. 

Another situation is when we want to freeze the game—for example, when displaying a message that the player should be able to read without distraction. The show_message() method of the Breakout class uses this approach and calls time.sleep(). Here is the relevant code:

Gameplay

The gameplay part is where the rules of Breakout come to play (see what I did there?). Gameplay is about moving the different objects in response to the events and changing the game state based on their interactions.

Moving the Paddle

You saw earlier that the Paddle class responds to arrow keys by updating its moving_left and moving_right fields. The actual movement happens in the update() method. There is some computation going on here if the paddle is close to the left or right edge of the screen. We don't want the paddle to move beyond the edges of the screen (including a predefined offset). 

So if the movement would have taken it beyond the edge, the code adjusts the movement to stop exactly at the edge. Since the paddle is only moving horizontally, the vertical component of the movement is always zero. 

Moving the Ball

The ball just uses the functionality of the GameObject base class, which moves game objects based on their speed (with horizontal and vertical components). The speed of the ball is determined by many factors in the Breakout class that you'll see soon. Since moving is just adding the speed to the current position, the direction the ball is moving is fully determined by its speed along the horizontal and vertical axes.

Setting the Initial Ball Speed

The ball in Breakout appears out of nowhere at the beginning of the game every time the player loses a life. It just materializes out of the ether and starts dropping either straight down or at a slight angle. When the ball is created in the create_ball() method, it receives a speed with a random horizontal component between -2 and 2 and a vertical component, which is determined in the config.py module (currently set to 3). 

Conclusion

In this part, we covered event handling such as key presses, mouse movement, and mouse clicks. We also dove into some of the gameplay elements of Breakout such moving the paddle, moving the ball, and controlling the ball's speed. 

Remember also to see what we have available for sale and for study in the Envato Market if you're looking to study more Python-related material.

In part four, we will deal with the important topic of collision detection and see what happens when the ball hits various game objects like the paddle, bricks, and even the walls, ceiling, and the floor. 

Then we'll turn our attention to the game menu. We'll create custom buttons that we'll use as a menu we can show and hide as necessary.


by Gigi Sayfan via Envato Tuts+ Code

7 Ways to Use Instagram Video for Business

Wondering how to create Instagram videos that will resonate with your audience? Looking for inspiration? In this article, you’ll discover seven ways to use Instagram video to enhance your stories and timeline with engaging content. #1: Integrate Instagram Stories Video An estimated 250+ million active users view Instagram Stories every day. Because Stories content has [...]

This post 7 Ways to Use Instagram Video for Business first appeared on .
- Your Guide to the Social Media Jungle


by Victor Blasco via

Highly Effective Healthy Habits of Working Online - #Infographic

Working from home is one of the biggest dreams of many employees these days. While it comes with its own challenges, the benefits can vastly outweigh any of these hesitations. If you’ve discovered you work your best outside of an office environment, here are some practices to stay fit when your...

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

by Web Desk via Digital Information World