Wednesday, August 2, 2017

Nuxt.js: A Universal Vue.js Application Framework

Universal (or Isomorphic) JavaScript is a term that has become very common in the JavaScript community. It is used to describe JavaScript code that can execute both on the client and the server.

Many modern JavaScript frameworks, like Vue.js, are aimed at building Single Page Applications (SPAs). This is done to improve the user experience and make the app seem faster since users can see updates to pages instantaneously. While this has a lot of advantages, it also has a couple of disadvantages, such as long "time to content" when initially loading the app as the browser retrieves the JavaScript bundle, and some search engine web crawlers or social network robots will not see the entire loaded app when they crawl your web pages.

Server-side Rendering of JavaScript is about preloading JavaScript applications on a web server and sending rendered HTML as the response to a browser request for a page.

Building Server-side rendered JavaScript apps can be a bit tedious, as a lot of configuration needs to be done before you even start coding. This is the problem Nuxt.js aims to solve for Vue.js applications.

What is Nuxt.js

Simply put, Nuxt.js is a framework that helps you build Server Rendered Vue.js applications easily. It abstracts most of the complex configuration involved in managing things like asynchronous data, middleware, and routing. It is similar to Angular Universal for Angular, and Next.js for React.

According to the Nuxt.js docs "its main scope is UI rendering while abstracting away the client/server distribution."

Static Generation

Another great feature of Nuxt.js is its ability to generate static websites with the generate command. It is pretty cool and provides features similar to popular static generation tools like Jekyll.

Under the Hood of Nuxt.js

In addition to Vue.js 2.0, Nuxt.js includes the following: Vue-Router, Vue-Meta and Vuex (only included when using the store option). This is great, as it takes away the burden of manually including and configuring different libraries needed for developing a Server Rendered Vue.js application. Nuxt.js does all this out of the box, while still maintaining a total size of 28kb min+gzip (31kb with vuex).

Nuxt.js also uses Webpack with vue-loader and babel-loader to bundle, code-split and minify code.

How it works

This is what happens when a user visits a Nuxt.js app or navigates to one of its pages via <nuxt-link>:

  1. When the user initially visits the app, if the nuxtServerInit action is defined in the store, Nuxt.js will call it and update the store.
  2. Next, it executes any existing middleware for the page being visited. Nuxt checks the nuxt.config.js file first for global middleware, then checks the matching layout file (for the requested page), and finally checks the page and its children for middleware — middleware are prioritized in that order.
  3. If the route being visited is a dynamic route, and a validate() method exists for it, the route is validated.
  4. Then, Nuxt.js calls the asyncData() and fetch() methods to load data before rendering the page. The asyncData() method is used for fetching data and rendering it on the server-side, while the fetch() method is used to fill the store before rendering the page.
  5. At the final step, the page (containing all the proper data) is rendered.

These actions are portrayed properly in this schema, gotten from the Nuxt docs:

Nuxt.js Schema

Creating A Serverless Static Site With Nuxt.js

Let's get our hands dirty with some code and create a simple static generated blog with Nuxt.js. We will assume our posts are fetched from an API and will mock the response with a static JSON file.

To follow along properly, a working knowledge of Vue.js is needed. You can check out Jack Franklin's great getting started guide for Vue.js 2.0 if you're a newbie to the framework. I will also be using ES6 Syntax, and you can get a refresher on that here: http://ift.tt/2lsFbvU.

Our final app will look like this:

Nuxt SSR Blog

The entire code for this article can be seen here on GitHub, and you can check out the demo here.

Application Setup and Configuration

The easiest way to get started with Nuxt.js is to use the template created by the Nuxt team. We can install it to our project (ssr-blog) quickly with vue-cli:

vue init nuxt/starter ssr-blog

Note: If you don't have vue-cli installed, you have to run npm install -g vue-cli first, to install it.

Next, we install the project's dependencies:

cd ssr-blog
npm install

Now we can launch the app:

npm run dev

If all goes well, you should be able to visit http://localhost:3000 to see the Nuxt.js template starter page. You can even view the page's source, to see that all content generated on the page was rendered on the server and sent as HTML to the browser.

Next, we can do some simple configuration in the nuxt.config.js file. We will add a few options:

// ./nuxt.config.js

module.exports = {
  /*
   * Headers of the page
   */
  head: {
    titleTemplate: '%s | Awesome JS SSR Blog',
    // ...
    link: [
      // ...
      { 
        rel: 'stylesheet', 
        href: 'http://ift.tt/2uxIolw' 
      }
    ]
  },
  // ...
}

In the above config file, we simply specify the title template to be used for the application via the titleTemplate option. Setting the title option in the individual pages or layouts will inject the title value into the %s placeholder in titleTemplate before being rendered.

We also pulled in my current CSS framework of choice, Bulma, to take advantage of some preset styling. This was done via the link option.

Note: Nuxt.js uses vue-meta to update the headers and HTML attributes of our apps. So you can take a look at it for a better understanding of how the headers are being set.

Now we can take the next couple of step by adding our blog's pages and functionalities.

Working with Page Layouts

First, we will define a custom base layout for all our pages. We can extend the main Nuxt.js layout by updating the layouts/default.vue file:

Continue reading %Nuxt.js: A Universal Vue.js Application Framework%


by Olayinka Omole via SitePoint

#301: A Pure CSS Alternative to Bootstrap

Frontend Focus
Issue 301 — August 2, 2017
A site logo linking to the homepage is not always enough. Here’s some best practices for that key link.
Nielsen Norman Group

A back to basics CSS starter kit “for when you don’t need the whole boot”.
Cory LaViska

Work is underway on standardizing an API for creating extensions that are browser interoperable, as is possible with the non-formalized WebExtensions API.
W3C

2017 predictions for the key and rising JavaScript libraries and frameworks and JS’s New Frontiers in this whitepaper.
Telerik   Sponsor

Elm is a ‘compile to JavaScript’ language for declaratively building front-end Web interfaces. This is one company’s experience with it.
Christian Charukiewicz

..includes Paint Timing API, font loading controls with the CSS font-display property and WebAssembly. Video round-up of features here.
Google Developers

See how you can get attractive webfont visuals, good performance and reliable functionality by properly employing a finely-tuned fallback.
Front End Center

Some more thoughts following last week’s announcement that Adobe is to end support for Flash. Brian notes that “Flash helped make the web what it is today”.
Brian Rinaldi

Jobs

Can't find the right job? Want companies to apply to you? Try Hired.com.

In Brief

Updates to Media Playback in Chrome 61 news
On Android, when a video is playing, rotating the device will automatically put it fullscreen.
Google Developers

Build your first Javascript, Android, or iOS app with MongoDB Stitch tutorial
Get started with the beta release of MongoDB's backend-as-a-service with step-by-step tutorials and sample apps.
MONGODB  Sponsor

How to Create An Animated Loader with Nothing But CSS tutorial
Julien Benchetrit

The Lightest Grays You Can Use While Maintaining Good Contrast tutorial
#767676 is relatively safe.
Brent Jackson

Wes Bos and Scott Tolinski on CSS Preprocessors and Structuring CSS podcast
Syntax Podcast

How I Built a Wind Map with WebGL story
Vladimir Agafonkin

Apple’s Refusal to Support PWAs Is A Detriment to Future of The Web opinion
Greg Blass

What is Timeless Web Design? opinion
How would you design a site to look good 10 years from now?
Chris Coyier

The Browser Statistics That Matter opinion
“The browser statistics that matter are the browser usage statics of your web site, and nobody else’s.”
Chris Coyier

Can QML Become The Next Standard for Web UI? opinion
Martin Kutny

Explore the Powerful Features of the ExtReact Grid for React Web Apps 
Try ExtReact and see how to easily add the grid and many other data-driven components into your apps.
Sencha, Inc.  Sponsor

A 'Gigantic' List of 1000+ Useful Frontend Tools and Resources tools
Tim Navrotskyy

GridBugs: A Community Curated List of CSS Grid Layout Bugs tools
Rachel Andrew

Chromeless: Chrome Automation Made Simple code
A TypeScript browser automation library for controlling Chrome.
Graphcool

image-compressor: A Simple JavaScript Image Compressor code
Reduce image sizes client-side before uploading? Demo.
Xkeshi

A Pure CSS 5-Star Rating Control demo
CodePen


by via Frontend Focus

Replaced Elements in HTML: Myths and Realities

Some HTML elements have always caused headaches for front-end developers everywhere, like iframes, applets, embedded objects or form controls. One could never have complete control over their display, because they look different from one browser to another, from one OS to another.

Replaced Element Myths

Countless libraries and frameworks created replacements, from jQueryUI to Bootstrap, and many more. But have you ever wondered why those elements behave the way they do? Some voices (including a few well-known websites) will point their finger to a fairly obscure definition from W3C, namely the one concerning replaced elements. But are they 100% right? This is the quest we will chase together today.

What are Replaced Elements?

Any good quest must start with research. Therefore let’s have a look at what the official specs say a replaced element is:

An element whose content is outside the scope of the CSS formatting model, such as an image, embedded document, or applet. For example, the content of the HTML IMG element is often replaced by the image that its “src” attribute designates. Replaced elements often have intrinsic dimensions: an intrinsic width, an intrinsic height, and an intrinsic ratio. For example, a bitmap image has an intrinsic width and an intrinsic height specified in absolute units (from which the intrinsic ratio can obviously be determined). On the other hand, other documents may not have any intrinsic dimensions (for example, a blank HTML document).

Source: 3. Conformance: Requirements and Recommendations > 3.1 - Definitions

So far, so good - we got a general description of what a replaced element is. Before we go deeper into this spec section, let’s make a small detour and clarify the “intrinsic dimensions” part.

What are Intrinsic Dimensions?

The best definition available now for intrinsic dimensions comes from the CSS Image Values and Replaced Content Module Level 3 document:

The term intrinsic dimensions refers to the set of the intrinsic height, intrinsic width, and intrinsic aspect ratio (the ratio between the width and height), each of which may or may not exist for a given object. These intrinsic dimensions represent a preferred or natural size of the object itself; that is, they are not a function of the context in which the object is used. CSS does not define how the intrinsic dimensions are found in general.

Here are some examples:

  • A normal image has all three dimensions: width, height and aspect ratio.
  • An SVG image can have only the aspect ratio. Its scaling nature means that the width and height are not restricted to a single value.
  • An empty HTML page, inserted via an iframe element has no dimensions at all.

The way these properties are tied to one another means that there can be no object with only two dimensions. Knowing two of them automatically determines the third one.

Overall this means that such an object, when placed into the page, will provide these intrinsic dimensions to the document so that they can be rendered properly. This information will be useful later, but for now, let’s return to the main path.

Replaced Elements in the Real World

For a full description of the replaced elements we need to go to a different resource, namely the Rendering section of the HTML Living Standard document. As one goes deeper into the specs, it’s easy to see how this topic can be confusing. This is because some HTML elements act as replaced elements all the time, while other do it only in specific circumstances.

Fortunately the Subsection 14.4 gives us all the information we need to properly understand each case.

Embedded content

The first category of replaced elements is embedded content. This includes any element that imports another resource into the document, or content from another vocabulary that is inserted into the document. These external resources, by their own nature, have the intrinsic dimensions that match the requirements of the definition.

The main elements in this category are embed, iframe, and video. These elements are always treated as replaced elements because they always import external content into your document.

Things are a bit more complicated with elements that fall into this category only in special circumstances:

  • applet - Treated as a replaced element when it represents a plugin, otherwise it’s treated as an ordinary element.
  • audio - Treated as a replaced element only when it is “exposing a user interface element”. Will render about one line high, as wide as is necessary to expose the user agent’s user interface features.
  • object - Treated as a replaced element when it represents an image, plugin, or nested browsing context (similar to an iframe).
  • canvas - Treated as a replaced element when it represents embedded content. That is, it contains the element’s bitmap, if any, or else a transparent black bitmap with the same intrinsic dimensions as the element.

These are the only cases where the elements above are treated as replaced elements (which covers almost all cases where these elements are used). For full details on this, please see WHATWG’s rendering rules for embedded content.

Continue reading %Replaced Elements in HTML: Myths and Realities%


by Adrian Sandu via SitePoint

10 Web Design Trends You Need to Be Aware of in 2017

2017 is already starting to prove an exciting year for web design. Let's look at some of the trends that will become more important as the year progresses: 1. Move Over Raymond, Everybody Loves VideoLet’s all agree on one thing first: car karaoke videos should go in 2017. Please? Okay, so...

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

by DIW via Digital Information World

10 Must Know Image Optimization Tips

If you run an online store, image optimization is an art that you want to master. From attracting shoppers perusing Google images to reducing site load time - image optimization can be an important part of building a successful ecommerce website. Have you ever stayed up at night wondering: Why is...

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

by DIW via Digital Information World

How to Split Test Your Way to Facebook Ads Success

Want to lower the cost per conversion of your Facebook ads? Wondering how to serve the right ad to the right audience? In this article, you’ll discover a six-step plan to test, analyze, and optimize Facebook ads, as well as the audience segments you target. Let Facebook Split Test Multiple Ad Variations When you run [...]

This post How to Split Test Your Way to Facebook Ads Success first appeared on .
- Your Guide to the Social Media Jungle


by Azriel Ratz via

#169: How to Detect If Your Native App Is Installed From Your Site

Mobile Web Weekly August 2, 2017   #169
Brian Rinaldi recommends
Apple’s Refusal to Support Progressive Web Apps Is A Detriment to Future of The Web — The author argues that Apple’s stance to PWAs (or lack of) means developers “can’t just hop on the PWA train and forget about native apps completely”.
Greg Blass
Brian Rinaldi recommends
W3C's Concerns Over Distributed and Syndicated Content — The W3C Technical Architecture Group shares a report over its concerns about strategies like AMP, Instant Articles and Apple News.
W3C
Sponsored
Linux cloud hosting starting at 1GB of RAM for $5/mo — Get a Linode server up and running in seconds. Simply choose your plan, distro and location and you’re ready to deploy your server. Use promo code MOBILEWEB20 for a $20 credit on a new account.
Linode

Holly Schinsky recommends
How to Detect If Your Native App Is Installed From Your Site — Chrome 59 introduced a new API allows you to determine if your native app is installed on a device.
Paul Kinlan
Peter Cooper recommends
Tabris.js 2.0 Released: Develop Native iOS and Android Apps in JS — 2.0 gets a more flexible UI framework, JSX support for declaratively defining UIs, and Windows 10 support (mobile and desktop).
EclipseSource
Peter Cooper recommends
Updates to Media Playback in Chrome 61 — On Android, when a video is playing, rotating the device will automatically put it fullscreen.
Google Developers
Brian Rinaldi recommends
Going Mobile: Wrapping An Existing Webapp in Cordova/PhoneGap — Some tips on how to approach wrapping an existing web app as a native mobile app with PhoneGap. Important to consider that in many cases this is not a recommended approach.
Abou Kone
Brian Rinaldi recommends
Building A Better Web with Automated Testing on Real Devices — Ben Schwarz argues the case for making the web fast for everyone with automated web app testing on real devices.
SitePoint
Sponsored
The Essential Guide to Queueing Theory — Queueing theory is one of the best ways to boost performance. This ebook demystifies the subject without requiring pages full of equations.
VividCortex

Chris Brandrick recommends
Hybrid Mobile Apps are Overtaking Native — The hybrid “space has evolved significantly for the better”.
Matt Netkow
Holly Schinsky recommends
Progressive Web Apps and the App Stores — Why one developer believes progressive web apps should be available in the app stores.
Trond Kjetil Bremnes
Holly Schinsky recommends
9 Mobile App Dev Trends To Watch — A look at the most predominant mobile app development trends for the rest of 2017.
Paweł Ha
Holly Schinsky recommends
Top Ionic Resources for Learning Hybrid App Development — A curated list of useful resources for learning and using Ionic 3 for building hybrid apps.
Gareth Dunne
Brian Rinaldi recommends
Determine Network Availability in a 'NativeScript with Angular' Mobile App — Learn how to check network connectivity, or in other terms, check for an internet connection in Android and iOS, using NativeScript and Angular.
The Polyglot Developer
Holly Schinsky recommends
Looking Back at PhoneGap Day EU 2017 — A look back at PhoneGap Day EU in Amsterdam recently.
Jen Gray
Holly Schinsky recommends
Optimized Ionic-Angular CSS Bundle for PWA — How to reduce the CSS bundle of your Ionic-Angular Progressive Web App by up to 91%.
Julien Renaux


by via Mobile Web Weekly