#227: Tidying Up

Show Description

It's time to clean all the things! Cassidy and Marie talk about how CodePen is cleaning up code, internal docs, and external docs. How does your team do spring cleaning?

Sponsor: Mux

Mux Video is an API-first platform that makes it easy for any developer to build beautiful video. Powered by data and designed by video experts, your video will work perfectly on every device, every time.

Mux Video handles storage, encoding, and delivery so you can focus on building your product. Live streaming is just as easy and Mux will scale with you as you grow, whether you're serving a few dozen streams or a few million.

Sign up for a free account and get $20 credit at Mux.com.

Show Links

CodePen Links

The post #227: Tidying Up appeared first on CodePen Blog.

Writing Java APIs Using Apache Atlas Client

In the previous blog, Data Governance using Apache ATLAS we discussed the advantages and use cases of using Apache Atlas as a data governance tool. In continuation to it, we will be discussing building our own Java APIs, which can interact with Apache Atlas using Apache atlas client to create new entities and types in it.

How to Create New Entities and Types Using Atlas Client

Atlas Client Maven Dependency

The following dependencies can be used to update pom.xml:

How to Make Simple End-To-End Tests With JavaTea

Although automated testing is an effective way to validate web applications, creating automated tests is time-consuming and maintaining the tests is painful. End-to-end testing is especially complex and taking time to execute.

To make it easier, this article proposes to use JavaTea, which is an end-to-end functional automation framework. It is built on Selenium WebDriver but it allows you to describe tests with less code compared to Selenium. The following three topics are focused in this article:

Comparing Popular WordPress Form Plugins

There are a lot of WordPress form plugins out there. And we mean a lot. If you’ve found yourself lost in a sea of forms, we’re here to rescue you with this comparison of the six most popular, general-purpose form plugins.

These are Gravity Forms, Contact Form 7, WPForms (Lite), Ninja Forms (Free), Formidable Forms (Free), and Caldera Forms (Free).

We’ll help you get much closer to making a decision by collecting the top features of these popular plugins here – so you don’t have to go sifting through their sites yourself.

Price

Contact Form 7 is the only plugin in this list that is fully free, but WPForms, Ninja Forms, Formidable Forms, and Caldera Forms all have a lite version. Of these free versions, Caldera Forms contains the most advanced features like conditional logic and multi-page.

Here’s a breakdown of the minimum to maximum prices for each premium plugin:

  • Formidable Forms: $99/year – $449/year.
  • Gravity Forms: $59/year – $259/year.
  • WPForms: $79/year – $599/year (not including introductory pricing).
  • Ninja Forms: $99/year – $499/year.
  • Caldera Forms: $164/year – $549/year.

Coins

Payment Integrations

Gravity Forms integrates with a variety of payment processors starting at the Pro license including PayPal, Stripe, Authorize.net, and 2Checkout. Caldera also supports numerous processors from the Individual license onward.

WPForms supports PayPal and Stripe at the Pro license. For Ninja Forms, the Personal license supports PayPal and Professional Stripe and Recurly. Formidable Forms’ Business license includes PayPal while Elite nets you Stripe and Authorize.net.

Contact Form 7 contains none by default. However, it’s the only form plugin that enables you to accept payments for free, albeit with third-party addons.

Person swiping a credit card.

Features

All these plugins except Contact Form 7 use a drag and drop live interface, and are responsive by default. You can use plugins and CSS to make CF7 responsive or have a different interface than the markup it uses to generate forms. All also come with some form of anti-spam protection.

Conditional logic, multi-page, and file uploading are among the most wanted features in a form builder.

You can find them in the base plans of every plugin – except Caldera Forms, which provides them in the lite version instead. Contact Form 7 includes only file uploading by default but – you know the drill – third-party plugins can add these extra features.

Conditional Fields for Contact Form 7

As for customization, Gravity Forms comes with 30+ form fields and plenty of options to configure. Contact Form 7 has various tags you can include, like text, email, URL, and checkbox input. WPForms offers pre-built templates as well as various helpful fields and addons that include more form types.

Ninja Forms also offers 30+ field types and templates to base your forms off of as well, plus plenty of fine-tuning options. The Personal plan includes extra layouts and styles to customize with.

Formidable Forms includes flexible layout design and a visual styling tool that lets you change colors and appearance on the spot. There are lots of custom fields as well. And Caldera Forms is built to match your theme styling, and there are dozens of field types to work with.

Out of these, Ninja Forms and Formidable forms include the most visual styling options, while WPForms, Gravity Forms, and Ninja Forms win in flexibility with many field and form types to choose form.

Final Comparison

Now that you’ve got the basics, let’s do a quick summary of these six form builders.

  • Gravity Forms is geared for businesses and professionals. It has a ton of useful integrations and is cheaply priced.
  • Contact Form 7 was made for individuals who need a no-frills form plugin, now. You’ll need to use third-party plugins to get the most out of it.
  • WPForms is designed for an all-around audience, beginners and advanced. It’s the most balanced of these with a good number of features and integrations. Simple but powerful.
  • Ninja Forms is defined by the sheer amount of addons available for it. Purchasing plans are centered around those addons – but its free version makes a decent simple form builder even without them.
  • Formidable Forms is great for developers as well as general users. It’s powerful, cheap, and devs will love using its API to extend it.
  • And Caldera Forms is a great one for beginners and businesses both who need an easy-to-set-up plugin. It has the most expensive entry price, but this is balanced by the advanced features available in the free version.

Armed with this knowledge, you should be able to choose a form plugin that perfectly suits your needs. We hope this helped you find what you were looking for – now get out there and start building your first form!

State of CSS 2019 Survey Results: Top Frameworks Rank Low in Satisfaction, JavaScript Proficiency is on the Rise

State of CSS Survey

The first ever State of CSS survey results have been published. The data includes responses from more than 11,000 developers in 135 countries. Respondents identified themselves as male (84.71%), female (9.9%), non-binary/third gender (0.86%), and “prefer not to say” (2.62%).

Sacha Greif and Raphaël Benitte, creators of the survey, said it’s skewed towards early adopters, since the sample size is a fairly small selection of the overall CSS developer community. Greif and Benitte also created the State of JS survey, which is where 31.5% of respondents heard about the CSS survey, so the data is also slanted towards the “back of the front-end,” developers who use JavaScript in their front-end work. They concluded that this data is a good preview of where the mainstream side of the ecosystem will be a few years from now.

The majority of respondents indicated that they are fairly confident about their back-end proficiency, with 62.49% identifying themselves as possessing intermediate or advanced backend skills. This trend sets the bar higher for developers who are looking to present a competitive skill-set in the CSS workforce.

The results seem clearly bent towards the JavaScript-proficient segment of CSS developers, with a whopping 80.54% rating their JavaScript proficiency at Intermediate to Expert level.

The summary includes a highly detailed look at different CSS-related technologies, such as preprocessors, methodologies, frameworks, and CSS-in-JS, with differently colored segments representing whether developers have favorable or negative opinions on each.

The results contain data visualizations showing which CSS features and technologies developers know about and/or have used in their work. Flexbox (94.4%) and Grid (54.4%) are among the most widely used layout tools. The frameworks section revealed some surprising results, with a few of the lesser-known frameworks, like Tailwind, Bulma, PureCSS, and Tachyon ranking highest in interest and satisfaction. The most well-known frameworks, Bootstrap and Foundation, fall at the bottom of the satisfaction scale.

These results are fairly representative of early adopters of new technologies in the CSS ecosystem, covering features and frameworks that are not yet mainstream. Greif and Benitte predict that even though CSS seems to be evolving slowly, mastering the newer technologies will become more important for developers who want to remain competitive.

For a more detailed look at other areas, such as typography, interactions, animations, and even what pseudo CSS selectors and form-related selectors developers use in their work, check out the full range of results at 2019.stateofcss.com.

Getting to Know the useReducer React Hook

useReducer is one of a handful of React hooks that shipped in React 16.7.0. It accepts a reducer function with the application initial state, returns the current application state, then dispatches a function.

Here is an example of how it is used;

const [state, dispatch] = useReducer(reducer, initialState);

What’s the good for? Well, think about any situation where having the first loaded state of the application might be nice. Let’s say the starting point on an interactive map. Maybe it’s an app that lets the user build a custom car with custom options from a default model. Here’s a pretty neat demo of a calculator app that puts useRedcuer to use in order to reset the calculator to a default state of zero when clearing it out.

See the Pen
Basic React Hook Calculator
by Gianpierangelo De Palma (@dpgian)
on CodePen.

We’re going to dig into a couple more examples in this post, but let’s first look at the hook itself to get a better idea of what it is and what exactly it does when it’s used.

The almighty reducer

It’s tough to talk about useState without also mentioning JavaScript’s reduce method. We linked it up at the very top, but Sarah’s post is an excellent overview of reducers and helps set the state for where we’re going here.

The first and most important thing to understand about a reducer is that it will always only return one value. The job of a reducer is to reduce. That one value can be a number, a string, an array or an object, but it will always only be one. Reducers are really great for a lot of things, but they're especially useful for applying a bit of logic to a group of values and ending up with another single result.

So, if we have an array of numbers, reduce will distill it down to a single number that adds up for as many times as there are values. Say we have this simple array:

const numbers = [1, 2, 3]

...and we have a function that logs each time our reducer makes a calculation into the console. This will help us see how reduce distills the array into a single number.

const reducer = function (tally, number) { 
	console.log(`Tally: ${tally}, Next number: ${number}, New Total: ${tally + number}`)
	return tally + number
}

Now let’s run a reducer on it. As we saw earlier, reduce takes dispatches a function that runs against a default state. Let’s plug our reducer function and an initial value of zero in there.

const total = numbers.reduce(reducer, 0)

Here’s what gets logged to the console:

"Tally: 0, Next number: 1, New Total: 1"
"Tally: 1, Next number: 2, New Total: 3"
"Tally: 3, Next number: 3, New Total: 6"

See how reduce takes an initial value and builds on it as each number in the array is added to it until we get a final value? In this case, that final value is 6.

I also really like this (modified) example from Dave Ceddia that shows how reduce can be used on an array of letters to spell a word:

var letters = ['r', 'e', 'd', 'u', 'c', 'e'];

// `reduce` takes 2 arguments:
//   - a function to do the reducing (you might say, a "reducer")
//   - an initial value for accumulatedResult
var word = letters.reduce(
	function(accumulatedResult, arrayItem) {
		return accumulatedResult + arrayItem;
	},
''); // <-- notice this empty string argument: it's the initial value

console.log(word) // => "reduce"

useReducer works with states and actions

OK, that was a lot of refresher to get what we’re really talking about: userReducer. It’s important to get all this, though, because you may have noticed where we’re going now after having seen the way reduce fires a function against an initial value. It’s the same sort of concept, but returns two elements as an array, the current state and a dispatch function.

In other words:

const [state, dispatch] = useReducer(reducer, initialArg, init);

What’s up with that third init argument? It’s an optional value that will lazily create the initial state. That means we can calculate the initial state/value with an init function outside of the reducer instead of providing an explicit value. That’s handy if the initial value could be different, say based on a last saved state instead of a consistent value.

To get it working, we need to do a few things:

  • Define an initial state.
  • Provide a function that contains actions that update the state.
  • Trigger userReducer to dispatch an updated state that’s calculated relative to the initial state.

The classic example of this a counter application. In fact, that’s what React’s docs use to drive the concept home. Here’s that put into practice:

See the Pen
React useReducer 1
by Kingsley Silas Chijioke (@kinsomicrote)
on CodePen.

It’s a good example because it demonstrates how an initial state (a zero value) is used to calculate a new value each time an action is fired by clicking either the increase or decrease button. We could even throw in a “Reset" button in there to clear the total back to the initial state of zero.

Example: A Car Customizer

See the Pen
React useReducer - car example
by Geoff Graham (@geoffgraham)
on CodePen.

In this example, we are making the assumption that the user has selected a car to purchase. However, we want the app to allow the user to add extra options to the car. Each option has a price that adds to the base total.

First, we need to create the initial state which will consist of the car, an empty array to keep track of features, and an additional price that starts at $26,395 and a list of items in the store, so the user can pick what they want.

const initialState = {
  additionalPrice: 0,
  car: {
    price: 26395,
    name: "2019 Ford Mustang",
    image: "https://cdn.motor1.com/images/mgl/0AN2V/s1/2019-ford-mustang-bullitt.jpg",
    features: []
  },
  store: [
    { id: 1, name: "V-6 engine", price: 1500 },
    { id: 2, name: "Racing detail package", price: 1500 },
    { id: 3, name: "Premium sound system", price: 500 },
    { id: 4, name: "Rear spoiler", price: 250 }
  ]
};

Our reducer function will handle two things: the addition and removal of new items.

const reducer = (state, action) => {
  switch (action.type) {
    case "REMOVE_ITEM":
      return {
        ...state,
        additionalPrice: state.additionalPrice - action.item.price,
        car: { ...state.car, features: state.car.features.filter((x) => x.id !== action.item.id)},
        store: [...state.store, action.item]
      };
    case "BUY_ITEM":
      return {
        ...state,
        additionalPrice: state.additionalPrice + action.item.price,
        car: { ...state.car, features: [...state.car.features, action.item] },
        store: state.store.filter((x) => x.id !== action.item.id)
      }
    default:
      return state;
  }
}

When the user selects the item she wants, we update the features for the car, increase the additionalPrice and also remove the item from the store. We ensure that the other parts of the state remain as they are.
We do something similar when a user removes an item from the features list - reduce the additional price, return the item to the store.
Here is how the App component looks like.

const App = () => {
  const inputRef = useRef();
  const [state, dispatch] = useReducer(reducer, initialState);
  
  const removeFeature = (item) => {
    dispatch({ type: 'REMOVE_ITEM', item });
  }
  
  const buyItem = (item) => {
    dispatch({ type: 'BUY_ITEM', item })
  }
  
  return (
    <div>
      <div className="box">
        <figure className="image is-128x128">
          <img src={state.car.image} />
        </figure>
        <h2>{state.car.name}</h2>
        <p>Amount: ${state.car.price}</p>
        <div className="content">
          <h6>Extra items you bought:</h6>
          {state.car.features.length ? 
            (
              <ol type="1">
                {state.car.features.map((item) => (
                  <li key={item.id}>
                    <button
                      onClick={() => removeFeature(item)}
                      className="button">X
                    </button>
                    {item.name}
                  </li>
                ))}
              </ol>
            ) : <p>You can purchase items from the store.</p>
          }
        </div>
      </div>
      <div className="box">
        <div className="content">
          <h4>Store:</h4>
          {state.store.length ? 
            (
            <ol type="1">
              {state.store.map((item) => (
                <li key={item.id}>\
                  <button
                    onClick={() => buyItem(item)}
                    className="button">Buy
                  </button>
                  {item.name}
                </li>
              ))}
            </ol>
            ) : <p>No features</p>
          }
        </div>

        <div className="content">
        <h4>
          Total Amount: ${state.car.price + state.additionalPrice}
        </h4>
      </div>
      </div>
    </div>
  );
}

The actions that get dispatched contains the details of the selected item. We make use of the action type to determine how the reducer function will handle the updating of the state. You can see that the rendered view changes based on what you do - buying an item from the store removes the item from the store and adds it to the list of features. Also, the total amount gets updated. No doubt, there are some improvements that can be done to the application, this is only for learning purpose.

What about useState? Can’t we use that instead?

An astute reader may have been asking this all along. I mean, setState is generally the same thing, right? Return a stateful value and a function to re-render a component with that new value.

const [state, setState] = useState(initialState);

We could have even used the useState() hook in the counter example provided by the React docs. However, useReducer is preferred in cases where state has to go through complicated transitions. Kent C. Dodds wrote up a explanation of the differences between the two and (while he often reaches for setState) he provides a good use case for using userReducer instead:

If your one element of your state relies on the value of another element of your state, then it's almost always best to use useReducer

For example, imagine you have a tic-tac-toe game you're writing. You have one element of state called squares which is just an array of all the squares and their value[.]

My rule of thumb is to reach for useReducer to handle complex states, particularly where the initial state is based on the state of other elements.

Oh wait, we already have Redux for this!

Those of you who have worked with Redux already know everything we’ve covered here and that’s because it was designed to use the Context API to pass stored states between components — without having to pass props through other components to get there.

So, does useReducer replace Redux? Nope. I mean, you can basically make your own Redux by using it with the useContext hook, but that’s doesn’t mean Redux is useless; Redux still has plenty of other features and benefits worth considering.

Where have you used userReducer? Have you found clear-cut cases where it’s better than setState? Maybe you can experiment with the things we covered here to build something. Here are a few ideas:

  • A calendar that focus at today’s date but allows a user to select other dates. Maybe even add a “Today" button that returns the user to today’s date.
  • You can try improving on the car example - have a list of cars that users can purchase. You might have to define this in the initial state, then the user can add extra features they want with a charge. These features can be predefined, or defined by the user.

The post Getting to Know the useReducer React Hook appeared first on CSS-Tricks.

The Beginner’s Guide to HTML

There are nearly 1.7 billion websites worldwide. This number continues to grow each day.

What do all of these sites have in common? In one way or another, they all use some form of HTML. That’s why learning basic HTML is such a useful skill.

Here’s the thing. You can definitely build a website without having to write a line of code. But with that said, once your site is live you should still know how to read and some HTML on your own.

So whether you’re creating a new website, have an existing website, or you just want to learn more about coding, this is guide will serve as the perfect introduction to HTML for you.

Let’s start with the basics. What exactly is HTML?

This acronym stands for Hypertext Markup Language. Basically, it’s the standard format used to create web pages, web applications, and documents. This computer language is a series of code that is typically written in a text file and then saved as HTML. When viewed on a web browser, this code translates to a properly formatted blend of text and other media.

HTML is behind every web page you see online, including this page that you’re reading right now.

Understanding hypertext and markup language

As I’ve already mentioned, HTML stands for hypertext markup language. But those words don’t mean much to most people, so I want to break them down even further so you can fully understand the definition.

The word hypertext dates back more than 50 years. It was invented to describe links in a document that make it possible for a viewer to jump to another place in the document or to a completely new document. This is something that we see and use every day in the modern Internet.

Here’s a visual representation of what hypertext looks like.

Hypertext

I’m sure you’re familiar with hyperlinks, which is a form of hypertext.

As you browse online, you’ll see either http:// or https:// before every web page in your web browser. This stands for hypertext transfer protocol.

Markup language refers to how documents and web pages are displayed. You see words that are bold, italic, or larger on a page. But behind the scenes, the markup language is the reason why certain components appear differently on a page.

Markups are characterized by tags and attributes. Most of the time these tags come in pairs. There are start tags and end tags, which are also known as opening tags and closing tags.

When to use HTML

HTML is the default language for all websites on the Internet. But it’s also used for various types of documents, such as ebooks.

When an HTML document gets rendered by a web browser, all of the markup language and tags are hidden. The display automatically gets changed to display a reader-friendly version of the document (what you’re seeing right now).

Do you need to learn HTML to create a website?

The short answer is no. Unless you’re planning to build pages from scratch and pursue web development, you won’t necessarily need to know every single component of HTML.

You can probably get away without knowing HTML if you’re using a CMS, website builder, or blogging platform. For example, if you’re using WordPress as your blogging CMS, the visual editor automatically translates your text to HTML.

Wordpress Editor

Working in the visual editor will display content similar to a standard email message or Microsoft Word document.

With that said, there are times when visual editors don’t always work the way you want to. You might find yourself in a situation where you want to format something a certain way and it’s not getting displayed properly.

Furthermore, your HTML also needs to be optimized for non-human readers. Search engine bots are crawling your website for indexing purposes. The way that your HTML gets read will have an impact on your SEO.

Website accessibility also needs to be taken into consideration. Computers can translate web pages into sound for people with disabilities. They rely on the structure and quality of HTML for this.

While the platforms on the market today make it possible to operate a website without knowing HTML, it’s still in your best interest to learn the basics.

Choosing your HTML editor

For those of you who are planning to create web pages using HTML, you’ll need to use an HTML editor.

These editors are the best way to organize your code and keep everything clean. Editors are great because they recognize whenever a new tag is opened. These tags are automatically closed by the software, ensuring that your code doesn’t have bugs. This also limits the number of typing and keystrokes you have to make.

The best HTML editors let you preview your HTML to see how the content will look from a web browser. There are tons of options online. But I’ve narrowed down a handful of the top HTML editors for you to consider.

You can also practice HTML with this free tool from W3Schools. That’s what I’m going to use to show you examples of HTML as we continue.

HTML basics

Before you start writing HTML, you need to understand the three main components.

  • Tags
  • Attributes
  • Elements

These can be described as the building blocks or foundation of HTML. Once you learn what these are and how they work, it will be easier for you to move forward. I’ll go into greater detail on each of these below.

Tags

In short, tags are used to distinguish HTML code from normal text. The way your document gets displayed will be based on the tag instructions.

Here’s an example. Let’s say you want to make something bold.

Bold Example

The tag for bold is <b>, which is pictured above. This compares to the text above it, which is <p>, or a standard paragraph text.

Once the code is rendered, it’s displayed how we would normally see it on a web page, as you can see from the right side of the screenshot above.

Now let’s say you wanted to make something italicized. The HTML tag would look like this:

italicized example

Pretty straightforward, right?

All I’m doing is using the tags to change the way the text appears when it’s on a web page.

Take a look at those tags closely. Do you notice a difference between the opening tag and closing tag? The closing tags have a slash, indicating that the italics, bold, or whatever other tag you’re using stops here.

If that example above didn’t have a slash in the closing tag, anything written after it would continue to be italicized.

Hyperlinks are also created with tags. Here’s what the HTML tag would look like if I wanted to hyperlink to the Quick Sprout homepage.

Link Example

This tag is a little bit more in-depth than the bold and italics examples. But the same concept still applies.

There is an opening tag and closing tag with text in between. The way these tags are written determines what the result will look like on the web page.

Every web page starts with a <!DOCTYPE html>. Then the first line of the file says <html> as well. You can see this on the three examples that I showed you above. This tells browsers how to read the code.

Elements

An HTML element consists of the opening tag, closing tag, and the content in between the two.

So when we were going through different examples of tags, each example was a new element. For example, let’s take a look at some potential lines of HTML.

Element Example

When you look on the right side of the screen at the page version of this code, you see four total sentences and two paragraphs.

Now, look at the HTML code on the left side of this split screen. You can see how the three different elements are identified.

Elements can be simple, such as the bold example above, or they can be a bit more complex.

The document above starts with an open <body> tag, and also ends with a closed </body> tag. So everything within those two tags can also be considered one element. But within that entire body, there could be dozens, hundreds, or thousands of additional elements, depending on how long and complex your content is.

Attributes

For the most part, tags are used to define how content is displayed in HTML. But with that said, there are times when additional information within an element needs to be added.

In these instances, you would use an attribute to define a specific characteristic of the element in question. Attributes consist of two things:

  • Name
  • Value

They are placed inside the start tag of an element. Here’s an example to show you what I mean.

Attribution Example

The attribute used here is align=”center” and it falls within the <p> opening tag. It means that whatever text comes before the closing </p> tag will have a specific characteristic defined by the attribution.

In this case, the attribute said to center the text.

We saw another example of this earlier when I created a hyperlink for the Quick Sprout home page.

Beginner HTML cheat sheet

There are thousands of different ways you can write content in HTML. But if you’re just starting out with, there’s no reason for you to learn all of them right away.

Instead, I’ll show you some basic HTML tags and explain what they’re used for. Then you can practice applying them in an HTML editor.

Heading tags

<head> … </head>

These tags are used to showcase specific information on pages such as title tags and meta tags. Proper use of heading tags can increase your search engine traffic.

Title tags

<title> … </title>

Your title will appear within the header of the page. It will give search engine crawlers more information about the primary content of a particular page.

Paragraph tags

<p> … </p>

You’ve seen these throughout the examples that I showed you above. They denote a new paragraph of text.

Hyperlinks

<a href=”link”> … </a>

This tag and attribute is used to display the anchor text for hyperlinks. The full link would be written in between the quotation marks.

Images

<img />

Image tags are used to present image files on the page.

Tables

<table> … </table>

This tag contains all of the information related to content in a table. It also identifies content as a table.

Footers

<footer> … </footer>

Anything in between these tags would be in the footer block of a page.

Conclusion

Every website uses HTML. So if you’re building a website or currently manage a website, it’s in your best interest to know what’s going on behind the scenes of your web pages.

I’m not suggesting that you should go out and start building pages from scratch without any experience as a developer. There’s really no reason for that.

But you should have a basic understanding of what HTML is, how it works, and where to edit it on your website.

Here’s what I suggest. Use one of the HTML editors that I showed you earlier to practice your basic coding skills. Then just go through and try to replicate some of the examples that I covered in this beginner guide.

That’s the best way to get your feet wet with HTML if you don’t have any experience with it.

What Web Designers Can Do To Speed Up Mobile Websites

What Web Designers Can Do To Speed Up Mobile Websites

What Web Designers Can Do To Speed Up Mobile Websites

Suzanne Scacca

I recently wrote a blog post for a web designer client about page speed and why it matters. What I didn’t know before writing it was that her agency was struggling to optimize their mobile websites for speed. As a result, she came back to me concerned with publishing a post on a strategy her agency had yet to adopt successfully.

She was torn though. She understood how important mobile page speeds were to the user experience and, by proxy, SEO. However, their focus has always been on making a great-looking and effective design. Something like page speed optimization was always left to the developers to worry about.

In the end, we decided to hold on publishing it until they could get their own website as well as their clients’ sites properly optimized. In the meantime, it got me thinking:

Is there anything designers can do when creating mobile websites to help developers optimize for speed?

Developers are already optimizing front end performance with:

  • Fast web hosting
  • CDNs
  • Clean coding practices
  • Caching
  • Minification
  • Image optimization
  • And more

So, is there anything left?

To me, this is a lot like how search optimization is handled. As a writer, I take care of the on-page optimizations while the developer I hand content over to does the technical SEO stuff. Web designers and developers can easily tackle the parts of speed optimization that are in each of their wheelhouses.

Understanding What “Slow” Means On The Mobile Web

There are a number of tools to help you analyze page speeds and implement various fixes to improve them. One tool that’s particularly helpful is called Lighthouse. The only thing is, it’s meant for web developers.

Instead, I suggest that web designers use another Google testing tool called Test My Site.

Test My Site speed test
Test My Site is a mobile page speed testing tool from Think with Google. (Source: Test My Site) (Large preview)

This is strictly for those who want to get a quick evaluation of their mobile site speed. All you need to do is enter your domain name into the field and let the test run.

Test My Site results example
An example of your page speed test results from Test My Site. (Source: Test My Site) (Large preview)

What I like about this tool compared to other site speed tests is that it’s all spelled out for you in layman’s terms. In this case, my website is “slow”, even when served on 4G networks. Although we’ve been told for years that visitors are willing to wait three seconds for a web page to load, Google considers 2.9 seconds too long. (Which I wholeheartedly agree with.)

You can get an expanded report from Google that tells you how to speed up your mobile loading times, but the suggestions are no different than the updates you’d make on the development side. For example:

Think with Google report suggestions
Think with Google suggests the typical page speed optimizations. (Source: Test My Site) (Large preview)

We already know this. However, if you (or your developer) haven’t yet implemented any of these fixes, this is a good checklist to work off of.

That said, I didn’t point you to this tool so you could keep doing the same optimizations over and over again, expecting the same result. What is it they always say about the definition of insanity?

Instead, I think you should use this as a quick gut check:

Is my mobile site fast enough in Google’s eyes? No? Then, it won’t be fast enough in your visitors’ eyes either.

And if you want to really drive that point home, scroll to the bottom of the Test My Site analysis page and run your numbers through the impact analysis calculator:

Test My Site revenue impact calculator
Test My Site’s revenue impact assessment. (Source: Test My Site) (Large preview)

If you aren’t completely convinced that you need to take your 3-second mobile speed down any further, look at the financial impact just .5 seconds would have on your monthly bottom line.

What Web Designers Can Do To Optimize Mobile Sites For Speed

Let the web developer handle all of the necessary speed optimizations like caching and file minification while you take on the following design tips and strategies:

1. Host Fonts From A CDN

There’s enough you have to worry about when it comes to designing fonts for the mobile experience that you probably don’t want to hear this… but custom web fonts suck when it comes to loading. In fact, there are two recent case studies that demonstrate why custom web fonts are detrimental to page loading speeds.

Thankfully, a CDN could end up being your saving grace.

The Downtime Monkey Example

The first comes from Downtime Monkey. In this case study, Downtime Monkey boasts a page speed improvement of 58% through a variety of optimizations — two of which pertained to how they served fonts to their site.

For their Font Awesome icons, they decided to host them from a CDN. However, Font Awesome’s own CDN proved unreliable, so they switched to the Bootstrap CDN. As a result, this saved them between 200 and 550 milliseconds per page load.

For their Google Font “Cabin”, they decided to host it from the Google CDN. What’s funny to note, however, is that when they ran a page speed test on the site afterwards, they received an optimization suggestion related to the font.

It seems that the link they put in the head of their site was slowing down the rendering of the page. So, they had to implement a workaround that would allow the font to load asynchronously without harming the display of the page as it loaded. They used Web Font Loader to fix the issue and ended up saving between 150 and 300 milliseconds per page load as a result.

Brian Jackson’s Test

Brian Jackson, the Chief Marketing Officer at Kinsta, wrote a post for KeyCDN that demonstrates the best way to serve custom web fonts on a website.

You can see in his example that he suggests a number of optimizations, like limiting which styles and character sets are available for use on the website. However, it’s his experimentation with CDN hosting that’s really interesting.

First, he isolated the most popular Google Fonts and tested how quickly they loaded through Google’s CDN:

Google font loading speeds
Open Sans was the fast Google Font. (Source: KeyCDN) (Large preview)

Open Sans loaded the fastest.

But that shouldn’t automatically make Open Sans the best choice if you’re trying to speed up your website. After all, Opens Sans is a Google Font that has to be served from Google’s servers. When compared against Arial, a web-safe font that isn’t pulled from an external source, this is what happened:

Arial vs Open Sans loading speeds
A comparison of loading speeds between Arial and Open Sans. (Source: KeyCDN) (Large preview)

Arial beat Open Sans by almost 200 milliseconds.

Before we move on, I’ll just say that this is one way to solve the slow-loading font dilemma: rather than use externally hosted fonts, use your system ones. They might not be as exciting to design with, but they won’t force users to sit around and wait for your website to load, costing you visitors and customers in the process.

You might be thinking that downloading and hosting your Google font would make more sense then. That way, you don’t have to compromise on which fonts you use and it’ll shave time off of their normal loading speeds. Right?

Well, Brian was curious about that, too, so he did a test:

Opens Sans - local host vs Google CDN
A comparison between Open Sans hosted locally vs. hosted on Google CDN. (Source: KeyCDN) (Large preview)

When served from a local server, Open Sans took 0.530 milliseconds to load. It’s not a huge difference, but it’s obviously not the right direction to go in.

So, what’s the conclusion? Well, you have a few options.

  1. You can use a web safe font and avoid the issues that come with using externally hosted fonts in the first place.
  2. You can use a Google font and make sure it’s hosted through Google’s CDN.
  3. You can download a Google font and upload it to your own CDN (if you can get it loading faster from there, that is).

Either way, hosting your fonts and icons from a location where they’ll load more quickly can help you optimize your website for performance.

2. Stop Using Cumbersome Design Elements

The following list is somewhat of a rehashing of topics that have been covered before, so I don’t want to waste your time trying to recreate the wheel here. However, I do think this strategy of removing unnecessary design elements (especially weightier ones) to optimize the mobile experience is one worth summarizing here:

Stop with On-Page Ads

When I wrote about elements you should ditch on mobile websites, I called out advertisements as one of the things you could easily toss out. I still stand by that conviction.

For starters, advertisements are served from a third party. Any time you have to call on another party’s servers, you’re further increasing your own loading times as you wait for them to deliver the content to your page.

Secondly, over 26% of the U.S. population alone uses ad-blocking technology on their devices, so they’re not likely to see your on-page ads anyway.

Statista - ad-blocking tech data
Statista data on the usage of ad-blocking technology in the U.S. (Source: Statista) (Large preview)

Instead, use monetization methods that move the advertising away from your website, increase your own on-site conversions and won’t drain your server’s resources:

  • Remarketing
    Let your tracking pixel follow visitors around the web and then serve your own ads on someone else’s site.
  • PPC
    There’s good money to be made if you can nail the pay-per-click advertising formula in Google.
  • Social media ads
    These are especially easy to run if your site is publishing new content on a regular basis and you have a compelling offer.
Stop With Pop-Ups

I know that Google says that mobile pop-ups are okay in certain instances. However, if you’re building a website with WordPress or another content management system and you’re using a plugin to create those pop-ups, that’s going to slow down your loading times. It might not be by much, but you’ll notice the difference.

ThemeIsle decided to do some analysis of how certain plugins affect WordPress website speeds. Here is what happened when they tested the effects each of these plugins had on the loading time:

Base loading time (in seconds) Loading time after install (in seconds) Change in %
Security plugins 0.93 s 1.13 s 21.50%
Backup plugins 0.93 s 0.94 s 1.07%
Contact form plugins 0.93 s 0.96 s 3.22%
SEO plugins 0.93 s 1.03 s 10.75%
E-commerce plugins 0.93 s 1.22 s 31.10%

Granted, some plugins are coded to be more lightweight than others, but there will always be some sort of difference felt in your loading times. Based on this data, the difference could be as small as .01 and as much as .29 seconds.

If you know that pop-ups aren’t really kosher on the mobile web anyway, why push your luck? Instead, take that promotional offer, cookie notice or announcement and place it on your web pages.

Stop With Cumbersome Contact Channels

Don’t forget about your website’s contact channels. In particular, you have to be careful about designing mobile forms. Of course, part of that has to do with how long it actually takes a user to fill one out. However, there’s also what a lengthy or multi-page form does to your loading speeds that you should think about.

In general, your mobile forms should be lean — only include what’s absolutely necessary.

There is an alternate school of thought to consider as well.

You could ditch the contact form altogether, something I discussed when talking about the trend of replacing mobile forms with chatbots. There are websites that have removed their forms and left information like FAQs, email addresses and phone numbers for visitors to use if they need to get in touch. That would certainly lighten things up from a loading standpoint. I just don’t know if it would be ideal for the user experience.

3. Create A Single-Page Website

The above tips are going to be the simplest and quickest ones to implement, so you should definitely start there if a client or web developer comes to you with issues of too-slow websites. However, if page speed tests still show that a site takes more than 2.5 seconds to load, consider a different approach to redesigning a website for the purposes of speed optimization.

As Adam Heitzman said in an article for Search Engine Journal:

“Single page sites typically convert much easier to mobile and users find them simple to navigate.”

But does that mean that a single-page website will always load more quickly than a multi-page website? Of course not. However, most professional designers choose a single-page design over multi-page for very specific purposes. DevriX has a nice graphic that sums this up:

DevriX graphic - single-page websites
DevriX sums up the limitations of single-page websites. (Source: DevriX) (Large preview)

To be clear, I’m not suggesting that you turn your website into a single-page application (SPA). If you want to speed up your client’s digital property with service workers, a PWA is a better solution. (More info on that in the next point.)

Instead, what I’m suggesting is that you convert a multi-page website into a single-page one if your client fulfills certain criteria:

  • Businesses with an extremely narrow and singular focus.
  • Websites that don’t require much content to get their point across.
  • A limited range of keywords you need to rank for.

That said, if you are designing a website that fits within those three criteria (or at least two out of three), you could realistically move your website to a more simplistic single-page design.

Because single-page websites force you to do more with less, the limited content and features naturally create a lightweight website. Even if you did push the limits slightly, you could still create a faster-loading website for mobile as Tempus does:

Test My Site report for Tempus
Test My Site reports that the Tempus website loads in 2.1 seconds. (Source: Test My Site) (Large preview)

What’s cool about this single-page website is that it doesn’t skimp on the extensive imagery needed to sell luxury homes. And, yet, its mobile site loads in 2.1 seconds.

On the other hand, not all single-page websites are built with speed in mind. Take developer Davide Marchet’s website:

Test My Site report for Davide Marchet
Test My Site reports that Davide Marchet’s website loads in 5.4 seconds. (Source: Test My Site) (Large preview)

Because it’s overloaded with animations, it takes 5.4 seconds for the page to load on mobile. You can even see this from the screenshot presented by Think with Google. The image seen there is actually the message that appears while the first animation loads in the background.

So, I would suggest being careful if you’re hoping to use a single-page design to solve your website’s performance woes. The design needs to be simple, super focused and unencumbered by scripts and animation effects that undo the benefits of trimming your content down to one page.

4. Turn Your Mobile Site Into A PWA

According to Google, there are three characteristics that define every PWA:

  1. Reliable
  2. Fast
  3. Engaging

Speed is an inherent part of progressive web apps thanks to the service workers they’re built with. Because service workers exist outside of the web browser and are not contingent on the speed of the user’s network, they load cached content for visitors more quickly.

I would also say that because the design of a PWA more closely resembles that of a native mobile app (at least the shell of it), this forces the design itself to be more trimmed-back than a mobile website.

If you’re struggling to speed up your website after implementing all of the traditional performance optimizations you’re supposed to, now would be a good time to turn your mobile website into a PWA.

Let me show you why:

Imagine you are planning a trip to Chicago with a friend. You’re out at a bar or coffee shop discussing the trip, then realize you have no idea where to stay. So, you do a search for “downtown Chicago hotels” on one of your smartphones.

You’re not thinking about purchasing a room yet; you just want to research your options. So, you click on the website links for two of the top listings Google provides you.

This is the progressive web app for the Best Western River North Hotel:

River North Hotel PWA
The home page of the Best Western River North Hotel PWA. (Source: Best Western River North Hotel) (Large preview)

This is the website of the Palmer House Hilton, a nearby hotel in downtown Chicago:

Palmer House Hilton website
The home page of the Palmer House Hilton website. (Source: Palmer House Hilton) (Large preview)

For starters, the PWA is a much better looking and easier to navigate on your smartphone, so it’s going to win major points there. There’s also the matter of speed:

Test My Site website speed comparison
Test My Site compares the two competing hotels’ loading speeds. (Source: Test My Site) (Large preview)

The River North Hotel loads in 2.4 seconds on mobile whereas its Hilton competitor loads in 4 seconds. (You can actually see in the Hilton screenshot that the site hadn’t completely loaded yet.) That’s a difference that visitors are sure to notice.

Even if we’re not doing a side-by-side comparison between the competing websites, the River North Hotel’s PWA blows its former mobile website out of the water.

Brewer Digital Marketing, the agency that developed the PWA for them, shared what happened after they made the switch over. The hotel saw a 300% increase in earnings and a 500% increase in nights booked with the PWA.

5. Convert Your Website Or Blog Into AMP

We have Google to thank for another speedy design trick for the mobile web. This one is called Accelerated Mobile Pages, or AMP, for short.

Initially, AMP was released to help publishers strip down their blog or news pages for faster loading on mobile devices. However, AMP is a web component framework you can use to design whole websites or just specific parts of them (like blog posts). Once implemented, pages load almost instantaneously from search.

Why is AMP so fast to load? There are a number of reasons:

With AMP, you can only load asynchronous JavaScript and inline CSS on your website, which means that your code won’t block or delay page rendering.

Images are also another source of slower loading times. However, AMP solves that issue by automatically loading the page layout before the resources (e.g. images, ads, etc.) Think of it as a form of lazy loading.

There’s a lot more to it, but the basic idea is that it cuts out the elements that tend to drag websites down and forces designers to mostly depend on lightweight HTML to build their pages.

If you want to see an example of this in action, you can look at pretty much any leading digital magazine or news site. If you’re unfamiliar with AMP content, simply look for the lightning bolt icon that appears next to the web page name in Google search. Like this:

The AMP lightning bolt symbol in search
Pages with the recognizable lightning bolt symbol were created using Google AMP. (Source: Google AMP) (Large preview)

Gizmodo is a good example of AMP content:

Gizmodo AMP
This Gizmodo AMP page loaded almost instantly from search results. (Source: Gizmodo) (Large preview)

In fact, when Gizmodo made the transition to AMP back in 2016, it saw huge lifts in terms of performance. Its page speeds increased by 300% and it got 50% more page impressions as a result.

If you really want to get the most out of AMP speeds, Mobify suggests pairing AMP with your PWA. That way, you can load your web pages lightning-fast for visitors:

First Page Load With AMP
Percent of Websites Load Time (seconds)
10% 0.3
20% 0.5
50% 1.1
60% 1.4
80% 2.2
90% 3.4
95% 5.2

Mobify reports on the loading times of AMP (Source: Mobify)

Then, sustain those fast-loading times with the PWA:

Subsequent Page Loads On PWA
Percent of Websites Load Time (seconds)
10% 0.6
20% 0.8
50% 1.4
60% 1.8
80% 3.0
90% 4.5
95% 6.2

Mobify reports on the loading times of PWAs (Source: Mobify)</>

Just be careful with AMP and PWAs.

Look at the tables above and you’ll see that some sites have implemented these speedy design tactics and they still don’t beat Google’s 2.5-second benchmark for mobile loading. Just because there is a promise of faster-loading web pages with both, that doesn’t necessarily mean your website will automatically be lightning-fast.

Wrapping Up

As Google does more to reward mobile websites over desktop, this isn’t really a matter you can table for much longer. All versions of your website — but mobile especially — must be optimized for the user experience.

That means the design, the code, the content and everything else within and around it must be optimized. Once the developer has taken care of the traditional performance optimizations to speed up the website, it’s time for the designer to make some changes of their own. In some cases, simple changes like how fonts are served through the website will help. In other cases, more drastic matters may need to be considered, like redesigning your website as a PWA.

First, consider how slowly your client’s website is loading. Then, examine what’s causing the biggest issue on mobile. Trim the fat, bit by bit, and see what you can do as a designer to complement the developer’s technical speed optimizations.

Smashing Editorial (ra, il)

How to Disable PHP Execution in Certain WordPress Directories

By default, WordPress makes certain directories writeable so that you and other authorized users on your website can easily upload themes, plugins, images, and videos to your website.

However this capability can be abused if it gets in the wrong hand such as hackers who can use it to upload backdoor access files or malware to your website.

These malicious files are often disguised as core WordPress files. They are mostly written in PHP and can run in the background to gain full access to every aspect of your website.

Sounds scary, right?

Don’t worry there is an easy fix for that. Basically, you’d simply disable PHP execution in certain directories where you don’t need it. Doing so, any PHP files will not run inside those directories.

In this article, we will show you how to disable PHP execution in WordPress using the .htaccess file.

How to Disable PHP Execution in Certain WordPress Directories

Disabling PHP Execution in Certain WordPress Directories Using .htaccess File

Most WordPress sites have a .htaccess file in the root folder. This is a powerful configuration file used to password protect admin area, disable directory browsing, generate SEO friendly URL structure, and more.

By default, the .htaccess file located in your WordPress website’s root folder, but you can also create and use it inside your inner WordPress directories.

To protect your website from backdoor access files, you need to create a .htaccess file and upload it to your site’s /wp-includes/ and /wp-content/uploads/ directories.

Simply create a blank file on your computer by using a text editor like Notepad (TextEdit on Mac). Save the file as .htaccess and paste the following code inside it.

<Files *.php>
deny from all
</Files>

Create htaccess File with Code to Disable PHP

Now save the file on your computer.

Next, you need to upload this file to /wp-includes/ and /wp-content/uploads/ folders on your WordPress hosting server.

You can upload it by using an FTP client or via File Manager app in your hosting account’s cPanel dashboard.

Upload htaccess file to your WordPress site

Once the .htaccess file with the above code is added, it will stop any PHP file to run in these directories.

Using this .htaccess trick helps you harden your WordPress security, but it is not a FIX for an already hacked WordPress site.

Backdoors are cleverly disguised and can already be hidden in plain sight.

If you want to check for possible backdoors on your website, then you need to activate Sucuri on your website.

Sucuri

Sucuri is the best WordPress security plugin on the market. It scans your website for possible threats, suspicious code, malware, and vulnerabilities.

It also effectively blocks most hacking attempts to even reach your website by adding a firewall between your site and suspicious traffic.

Most importantly, if your WordPress site gets hacked, then they will clean it up for you. To learn more, you can check our Sucuri review because we have been using their service for years.

We hope this article helped you to learn how to disable PHP execution in certain WordPress directories to harden your website security. If you are looking for a complete guide, check out our ultimate WordPress security guide.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Disable PHP Execution in Certain WordPress Directories appeared first on WPBeginner.