Every week users submit a lot of interesting stuff on our sister site Webdesigner News, highlighting great content from around the web that can be of interest to web designers.
The best way to keep track of all the great stories and news being posted is simply to check out the Webdesigner News site, however, in case you missed some here’s a quick and useful compilation of the most popular designer news that we curated from the past week.
Note that this is only a very small selection of the links that were posted, so don’t miss out and subscribe to our newsletter and follow the site daily for all the news.
Product Design Tools to Use in 2019
Google Photos is Making Photos Semi-public
84 Cognitive Biases You Should Exploit to Design Better Products
How Uber Redesigned its Interface for the Rest of the World
Everything You Need to Know About CSS Margins
Interaction Design Inspiration – Jul 2019
A New System for Designing Motion with Both Sketch and Figma by Google Design
Ways Web Designers Give Away their Time (Without Realizing it)
How do I Increase my Domain Authority in 2019?
DuckDuckGo Expands its Maps UI with a Few Familiar Features
Resource: The Website Directory
Building a Design System: Typography
Bamburgh UI Kit
Accessible CSS Generated Content
Managing Multiple Backgrounds with Custom Properties
The Spectrum of Maturity for Design Systems
Let’s Build a Web Server. Part 1
Creating Pixel Art with CSS
Butchery – Free Script Font
When You Can’t Find the Words, 65 New Emoji are Here for You
Dear Google, I’m Blocking You from my Website
50 Shades of Black: Effective Use of no Color
See the World’s Oldest Emoji in this New Archive of 650 Ancient Symbols
The 17 Coolest Fonts of 2019
How to Survive an Open Office
Want more? No problem! Keep track of top design news from around the web with Webdesigner News.
I recently drew up a wireframe for a code beautifier. The next day, I decided to turn it into a real tool. The whole project took less than two days to complete.
I’d been thinking about building a new code beautifier for a while. The idea isn’t unique, but every time I use someone else’s tool, I find myself reapplying the same settings and dodging advertisements every single time. ???
I wanted a simple tool that worked well without the hassle, so last week I grabbed some paper and started sketching one out. I’m a huge fan of wireframing by hand. There’s just something about pencil and paper that makes the design part of my brain work better than staring at a screen.
I was immediately inspired after drawing the wireframe. The next day, I took a break from my usual routine to turn it into a something real. ????
I knew I wanted the code editor to be the main focus of the tool, so I created a thin menu bar at the top that controls the mode (i.e. HTML, CSS, JavaScript) and settings. I eventually added an About button too.
The editor itself takes up most of the screen, but it blends in so you don’t really notice it. Instead of wasting space with instructions, I used a placeholder that disappears when you start typing.
At the bottom, I created a status bar that shows live stats about the code including the current mode, indentation settings, number of lines, number of characters, and document size in bytes. The right side of the status bar has a “Clear” and “Clean + Copy” button. The center has a logo shamelessly plugging my own service.
I don’t think many developers really code on phones, but I wanted this to work on mobile devices anyway. Aside from the usual responsive techniques, I had to watch the window size and adjust the tab position when the screen becomes too narrow.
I’m using flexbox and viewport units for vertical sizing. This was actually pretty easy to do with the exception of a little iOS quirk. Here’s a pen showing the basic wireframe. Notice how the textarea stretches to fill the unused space between the header and footer.
If you look at the JavaScript tab, you’ll see the iOS quirk and the workaround. I’m not sure how to feature detect something like this, so for now it’s just a simple device check.
Handling settings
I wanted to keep the most commonly used settings easy to access, but also expose advanced settings for each mode. To do this, I made the settings button a popover with a link to more advanced settings inside. When a setting is changed, the UI updates immediately and the settings are persisted to localStorage.
I took advantage of Vue.js here. Each setting gets mapped to a data property, and when one of them changes, the UI updates (if required) and I call saveSettings(). It works something like this.
function saveSettings() {
const settings = {};
// settingsToStore is an array of property names that will be persisted
// and "this" is referencing the current Vue model
settingsToStore.map(key => settings[key] = this[key]);
localStorage.setItem('settings', JSON.stringify(settings);
}
Every setting is a data property that gets synced to localStorage. This is a rather primitive way to store state, so I might update the app to use a state management library such as Vuex later on.
To restore settings, I have a restoreSettings() function that runs when the app starts up.
function restoreSettings() {
const json = localStorage.getItem('settings');
if (json) {
try {
const settings = JSON.parse(json);
Object.keys(settings).forEach(key => {
if (settingsToStore.includes(key)) {
this[key] = settings[key];
}
});
} catch (err) {
window.alert('There was an error loading your previous settings');
}
}
}
The function fetches settings from localStorage, then applies them one by one ensuring only valid settings in settingsToStore get imported.
The Advanced Settings link opens a dialog with tabs for each mode. Despite having over 30 settings total, everything is organized and easy to access so users won’t feel overwhelmed.
Applying themes
Dark mode is all the rage these days, so it’s enabled by default. There’s also a light theme for those who prefer it. The entire UI changes, except for popovers and dialogs.
I considered using prefers-color-scheme, which coincidentally landed in Firefox 67 recently, but I decided a toggle would probably be better. Browser support for the color theme preference query isn’t that great yet, plus developers are weird. (For example, I use macOS with the light theme, but my text editor is dark.)
Defining features
Coming up with feature ideas is fairly easy. It’s limiting features for an initial release that’s hard. Here are the most relevant features I shipped right away:
Beautifies HTML, CSS, and JavaScript code
Syntax highlighting with tag/bracket matching
Paste or drop files to load code
Auto-detects indentation preference based on pasted code or dropped file
Light and dark themes
Clean and copy in one click
Keyboard shortcuts
Most JS Beautify options are configurable
Settings get stored indefinitely in localStorage
Minimal UI without ads (just an unobtrusive plug to my own service) ?
I also threw in a few easter eggs for fun. Try refreshing the page, exploring shortcuts, and sharing it on Facebook or Twitter to find them. ?
The tools and libraries I used
I’m a big fan of Vue.js. It’s probably overkill for this project, but the Vue CLI let me start building with all the latest tooling via one simple command.
vue create beautify-code
I didn’t have to waste any time scaffolding, which helped me build this out quickly. Plus, Vue came in handy for things like live stats, changing themes, toggling settings, etc. I used various Element UI components for things like buttons, form elements, popovers, and dialogs.
The editor is powered by CodeMirror using custom styles. It’s a well-supported and fantastic project that I can’t recommend enough for in-browser code editing.
The library that does all the beautifying is called JS Beautify, which handles JavaScript, HTML, and CSS. JS Beautify runs on the client-side, so there’s really no backend to this app — your browser does all the work!
JS Beautify is incredibly easy to use. Install it with npm install js-beautify and run your code through the appropriate function.
import beautify from 'js-beautify';
const code = 'Your code here';
const settings = {
// Your settings here
};
// HTML
const html = beautify.html(code, settings)
// CSS
const css = beautify.css(code, settings)
// JavaScript
const js = beautify.js(code, settings)
Each function returns a string containing the beautified code. You can change how each language is output by passing in your own settings.
I’ve been asked a few times about Prettier, which is a comparable tool, so it’s worth mentioning that I chose JS Beautify because it’s less opinionated and more configurable. If there’s enough demand, I’ll consider adding an option to toggle between JS Beautify and Prettier.
I’ve used all of these libraries before, so integration was actually pretty easy. ?
This project was made possible by my app, Surreal CMS. If you’re looking for a great CMS for static websites, check it out — it’s free for personal, educational, and non-profit websites!
Oh, and if you’re wondering what editor I used… it’s Visual Studio Code. ????
This isn’t our first rodeo! I started ARTIFACT back in 2013 with Christopher Schmitt and Ari Stiles (the team behind the legendary In Control and CSS Dev conferences). At that time, the sudden avalanche of web-enabled mobile devices was throwing the web design community for a loop. How do we best leverage the recently-introduced Responsive Design techniques to adapt our designs to a spectrum of screen sizes?! What does that do to our workflows?! What happens to our beloved Photoshop comps?! How do we educate our clients and structure our billing cycles?! It was an exciting time when we needed to adjust our processes quickly to take on a radically new web viewing environment.
After four events in 2013 and 2014, ARTIFACT took a little hiatus, but we are back for a five-year reunion in 2019. We are returning to a landscape where a lot of the challenges we faced in 2013 have been figured out or, at the very least, have settled down (although there is always room for innovation and improvement).
Is our work making the web better done? Not by a long shot! Now that we’ve got a handle on the low-bar requirement of getting something readable on all those screens, we can focus our energy on higher-order challenges. How do we make our sites work easier for people of all abilities? How do we make our content, products, and services welcoming to everyone? Does our code need to be so bloated and complicated? How can we make our sites simpler and faster? How can I put new tools like CSS Grid, Progressive Web Apps, static sites, and animation to good use?
To that end, this time around ARTIFACT is expanding its focus from “designing for all the devices” to “designing for all the people.” Simply put, we want a web that doesn’t leave anyone out, and we’ve curated our program to address inclusivity, performance, and the ways that new possibilities on the web affect our workflow.
A web for everyone
Inclusive design—including accessibility, diversity, and internationalization—has been bubbling to the top of the collective consciousness of the web-crafting community. I’m incredibly encouraged to see articles, conference talks, and podcasts devoted to improving the reach of the web. At ARTIFACT, inclusivity is a major theme that winds its way throughout our program.
Benjamin Evans will talk about his efforts as the Inclusive Design Lead at AirBnB to create a user experience that does not alienate minority communities.
Accessibility expert Elle Waters will share best practices for integrating accessibility measures into our workflows..
We’ll also hear from David Dylan Thomas on how to recognize and address cognitive bias that can affect content and the overall user experience.
Even better performance
Visitors may also be turned away from our sites if pages take too long to load or use too much data. We know performance matters, yet sites on the whole grow more bloated with every passing year. Tim Kadlec (who knows more about performance than just about anybody) will examine the intersection of performance and inclusion in his talk “Outside Looking In” with lots of practical code examples for how to do better. We’ll also look at performance through the lens of Progressive Web Apps (presented by Jason Grigsby of Cloud Four). In fact, improving performance is a subtext to many of our developer-oriented talks.
Leveraging the modern browser
In the Good News Department, another big change since the first ARTIFACT is that browsers offer a lot more features out of the box, allowing us to leverage native browser behavior and simplify our code (Viva Performance!). Chris Ferdinandi will be demonstrating exactly that in his talk “Lean Web Development,” where he’ll point out ways that taking advantage of built-in browser functionality and writing JavaScript for just the interactivity you need may make a big framework unnecessary. Better native browser features also means un-learning some of our old coping mechanisms. We’ll get to delight at all the polyfills and workarounds that have been kicked to the curb since 2012 in Dave Rupert’s tale of “The Greatest Redesign Ever Told,” and we’ll see what best practices make sense going forward.
Workflow and process
One thing that hasn’t changed—and likely never will—is that never-ending hamster wheel of trying to keep up with an ever-changing web development landscape. I’m guessing that if you are reading CSS-Tricks right now, you know that feeling. The methods we use to build the web are always evolving with new tools, approaches, and possibilities, which is why best practices for adapting our workflows and processes have always been a central focus at ARTIFACT. This year is no different. Jen Simmons will share her thinking process for designing a CSS grid-based layout by live-coding a site before our very eyes. Design systems, which have become a cornerstone of large-scale site production, get the treatment in talks by Kim Williams, Dan Mall, and Brad Frost. (Dan and Brad are also running their acclaimed “Designer + Developer Collaboration Workflow” workshop on October 3.) Divya Sasidharan will show off the possibilities and performance advantages of static sites in her “JAMstackin” presentation, and we’ll get a glimpse of the future of web animation from Sarah Drasner. (She’s bringing her popular “Design for Developers” workshop on October 3 as well).
The web can always do better to serve the people who use it. We’re proud to provide an occasion for designers and developers who care about putting their users front and center to mingle and share ideas. And yes, there will be milkshakes! The very best milkshakes.
What can we do to cause “good trouble”? First of all, I think it needs to be friendly, helpful and meaningful actions that don’t impact other peoples’ lives. Secondly, it’s something we strongly believe in — it might be using simpler JavaScript methods, reducing the application size, a better toggle UI, publishing a book or building a business without selling user data to others. Whatever it is, it’s good to have a standpoint of view and talk about it.
It’s good to advocate others about accessibility problems, about how to listen better to others in a conversation, how to manage projects, products or even a company better. The most important thing on all these actions is to remember that they are helping other people and not impacting them as well as animals or our environment in general.
Doing something useful — as small as it might seem — is always a good thing. And don’t forget to honor your action just by smiling and being thankful for what you did!
News
Chrome 76 removes a couple of things like feature policy: lazyload, insecure usage of DeviceMotionEvent and the DeviceOrientationEvent. If you use them, please ensure you use a secure context by now or replace them by their successors.
Firefox 68 is out and this is new: BigInts for JavaScript, Accessibility Checks in DevTools, CSS Scroll Snapping and Marker Styling, access to cameras, microphones, and other media devices is no longer allowed in insecure contexts like plain HTTP. It’s now possible to resend a network request without editing the method, URL, parameters, and headers via DevTools, and a lot of (compatibility) fixes are included for CSS features as well.
Chrome 76 brings image support for the async clipboard API, making it easy to programmatically copy and paste image/png (currently, this is the only supported format though, unfortunately) images.
Have you heard of the concept of “good trouble”? Frank Chimero defines it as questioning and re-imagining the status quo, and having your actions stand in contrast to the norm. But the interview with the designer shows much more than a new concept, it’s challenging how we work today and how to do your own thing that doesn’t match the norm of the society.
Particularly, I like this quote here:
“Slow down, find a quiet place and create time for solitude so you can hear yourself. It’s so noisy out there.”
What if control is only an illusion? We would realize that the true nature of an experience is revealed only in the interplay with the people who use it and that an invalidated design is nothing but an opinion. Quite a thought that puts our assumptions and approach on projects into a different light.
Active Listening is a skill that helps us listening for meaning, and how the other person is feeling instead of that usual listening that focuses on ‘how can I reply or comment on this or how will we solve this?’. Buffer’s guide written by Marcus Wermuth is a great resource to learn and practice Active Listening.
Ben Werdmüller on doing well while doing good: This is a personal story about struggling with revenue, investments, third-party capital, trying to earn money on your own by selling your product while having free competitors and how to still produce good things while doing financially well.
Shape Up — Stop Running in Circles and Ship Work that Matters is a new, free online book by Ryan Singer about project management, leading a company and product. It’s amazing and while I only had time to flick through it quickly and read some individual chapters and sections, this will definitely become a resource to save and refer to regularly.
Going Beyond…
I was in the cinema last week to watch a movie about some people who created a farm. The trailer was nice and while I wasn’t 100% convinced of it, it was an evening where I was up to go out to watch a movie. So I did and it was good that I went to see “The Biggest Little Farm”. The farmer made the film himself as he’s a wildlife filmmaker so expect some quite stunning pictures and sequences of wildlife animals in there!
The most revealing part was how much of an impact only a handful of people can make out of desert land in a few years of time, and how much we as humans can influence wildlife, give a habitat to insects, and produce quality food while including CO2 from the air into our soil to make plants grow better, in order to restore nature and make an impact in the effort to fight climate change.
At several points during the movie, I was close to tears and I was extremely thankful that I’m able to have my little garden space as well where I can do similar things (though way smaller than their farm). If you’re up for something new, to learn something about food, meat, economy and how it all connects or how to create a beautiful green space out of desert, this movie is for you.
Last but not least, solar panels are a good way to produce renewable energy and it’s good usage of roofs. In China though, air pollution is currently so bad that solar panels sometimes stop working. Another reason to act quickly! If solar panels don’t work due to missing sunrays, our bodies will suffer the same lack of sunlight and we need it for our health.
What’s even better is that you don’t have to spend years mastering programming either. Thanks to numerous coding apps available for both Android and iOS devices, you can easily level up your coding skills even when you’re on the go.
In this post, we’ve rounded up the best coding apps that will help you learn to code like a pro.
SoloLearn
SoloLearn is an app available for both iOS and Android devices and it also has a web app so you can use it to learn to code from anywhere. The app offers a number of different courses in languages such as JavaScript, Python, Java, and more. The app offers free trial as well as paid monthly and yearly plans.
Encode
Encode is an Android app that offers lessons in programming in bite-sized portions. The app has programming challenges that you have to solve in order to progress further. It also includes practical examples and teaches you how to program in HTML, CSS, JavaScript, and Python. On top of that, the app has offline mode so you can continue learning even if you aren’t connected to the Internet.
Codemurai
Codemurai offers hundreds of bite-sized coding lessons that were created by industry experts on web development, mobile app, and game development. The app has lessons for languages that include HTML, CSS, JavaScript, Python, TypeScript, Angular 2, MongoDB, Node, React, and more. You will learn programming through fun coding challenges and then have the ability to test your knowledge with quizzes.
Mimo
Mimo is a programming app that allows you to develop programming skills that will help you develop an app or a game, make a website or become a hacker. Based on your preferences and interests, you will get a personalized track that will teach you the necessary skills. It’s available for both iOS and Android devices and offers courses in JavaScript, Ruby, Swift, C, C++, and other popular languages.
Grasshopper
Grasshopper is a free iOS and Android app that teaches you how to code through JavaScript puzzles that you have to solve in order to progress. This app is very easy to use as it allows you to use blocks and arrange them in a logical order in order to create a working code. You also get real-time feedback and unlock achievements as you become more proficient.
Programming Hero
Programming Hero is an Android-only app that offers personalized paths towards coding mastery. The emphasis of this app is on making coding fun and it does so through teaching you how to build your own game while learning how to code at the same time. The app also offers forums where you can chat with other app users and exchange knowledge and tips.
Tynker
While Tynker is primarily geared for kids and parents or educators looking to take their children’s and student’s education further, there’s a lot you can learn from this app. For starters, the app supports not only game design but also basics of robotics and more advanced languages such as JavaScript and Python. The app offers challenges, quizzes, and even level editors and character creation. The app is available for iOS devices.
Enki App
Try the Enki app if you want a personalized track that will allow you to improve your programming skills. You can easily track your progress as you learn Python, Linux, JavaScript, HTML, CSS, Java or Git. What makes this app different is the fact that you can set daily goals to learn programming and keep track of your streak. Each lesson offers a summary of the main concept for the day as well as an attached article that goes more in-depth. Enki is available for iOS and Android devices.
Programming Hub
Programming Hub was named Google Play’s Editor’s Choice app and with good reason. It supports a wide array of languages and delivers the lessons in bite-sized interactive lessons and courses. Supported languages include Java, C++, C programming, HTML, CSS, JavaScript, and more. What’s more, the app was developed in collaboration with Google experts. The app is available for both Android and iOS devices.
Easy Coder
Easy Coder is an Android app that focuses on teaching Java programming exclusively. The app provides step-by-step interactive lessons, quizzes, and programming challenges which will teach you the basic programming concepts and prepare you to develop your skills even further. Lessons are short and concise so that you consume them even if you’re on the go and the app also comes with practical examples to clarify the programming concepts.
Mobile Apps have become a go-to tactic for businesses around the globe.
There won’t be any organization in the world who hasn’t invested in this sector. Nowadays, mobile apps are not a fashion symbol; it has become a necessity. Those who don’t have mobile apps for their business will fall behind the competitors.
You can say that mobile apps have revolutionized every sector of the industry.
Therefore, it becomes essential for all of you to be aware of its latest trends.
Now, in the last few years, there is another innovation which took place.
People know this innovation as Chatbots, and it has taken the world by storm. Chatbots have become a real buzzword in the last few years or so. There won’t be anyone who hasn’t heard of Chatbots & its functionalities.
According to a survey by Gartner, 85% of the customer relationship will get maintained without any human intervention by 2020. That’s where Chatbots will play a massive role.
Therefore, it becomes vital to have in-depth knowledge about this trending technology. The Beginner’s Guide To Chatbot can be helpful in this regard, without any doubt.! Recently, Mobile Apps and Chatbots have emerged as two of the most significant players.
There is a massive debate going on the industry about which is the most impactful player. Experts believe that Chatbot is where the future belongs. So, you should know about it.
Chatbots vs. Mobile Apps has been one of the ongoing debates around the industry. Most of the people are favoring Chatbots over the Mobile Apps are in this aspect.
The question is, Why Chatbots over Mobile Apps? So, let’s analyze that aspect.
Why Chatbots Gets Preference Over Mobile?
In this section, we’ll provide you with a list of reasons for which Chatbots gets preference over Mobile Apps.
It will also help you to understand why experts are favoring Chatbots in the Chatbots vs. Mobile Apps contest.
So, let’s get the show started right here, right now.!
1. User Love Messenger Apps
Messenger Apps have become the talk of the town in the last few years or so. Facebook Messanger has been the most successful in this aspect. It has over 1 billion active users. These people use messenger to communicate with any brand. For that, Chatbots come into the picture.
Chatbots helps customer to know about the brand. It can also assist customers and solve their burning issues. Due to all these reasons, Chatbots have gained massive popularity among the audience. Nowadays, customers prefer talking to bots compared to representatives.
The reason behind that is the ability of Chatbots to understand the context of the question. It can provide intelligent answers as well. That’s why people have become a fan of messenger apps. So, you will see Chatbots beating mobile apps in the future. So, start working on this aspect soon.
2. Users Are Bored Of Apps
Mobile Apps have been around for a long time. Therefore, many experts believe that the saturation point is nearer. People have become bored with various apps. Unless you get an out of the box app, people are not going to use it. There are more than two billion apps for Android OS.
Add that to some million iOS app, and you will get crazy about that aspect. Most of the apps nowadays are complicated. You need to download them, and they take a chunk of your phone’s memory as well. Managing the smartphone memory has also become a massive issue for users.
For solving all those issues, Chatbots come into the picture. For using a Chatbot solution, you don’t need to download anything. It also doesn’t compromise your smartphone’s memory as well. That is the prime reason why Chatbots are going to replace mobile apps sooner rather than later.
3. Chatbots Bring Human Touch
Mobile Apps help you to solve all your daily routine problems and make your life easier. But, it can’t bring human touch into the picture. Chatbots can understand the human language, and based on that; it can provide accurate answers to the questions of customers. It could work well.
Chatbots make use of Natural Language Processing (NLP). The NLP-Based Chatbot Services can understand the syntax as well as the semantics of the human language. It can also understand what would be the reaction of the customer in a particular situation. So, that is an added advantage.
Now, when you talk about mobile apps, users have to navigate through the menu to find one option. That’s not the case with Chatbots. For using any bot, you don’t need to manage a lot of stuff. You have to install the software once and then; you can enjoy the benefits out of that.
4. Chatbots Are Simpler & Faster
One of the most significant benefits that you with Chatbots is that you don’t have to download anything for using bots. One time installation is good enough to get things started.
When it comes to Mobile Apps, that’s not the case. Therefore, you all can say that Chatbots are simpler and faster.
Chatbots brings us to an earlier era of computing where the command line was the need of the art. The only difference between those years and now is that the user can enter the command in natural language. The Chatbot can also help you to save a lot of precious time as well as money.
In today’s day and age, when life has become busy, people can’t afford to waste a second. That’s where Chatbots can rise above all. It can help you to perform the daily task in a matter of minutes. That is the reason why experts believe that the future will belong to Chatbots, for sure.
5. Cost Saving Option
If you think of the cost of developing, deploying, and maintain a mobile app for your business, then it would be massive.
The average price of developing a full-fledged mobile app is around $10000. If you also consider the platform for mobile applications, then that would add up to the budget.
On the other hand, Chatbots can help you to save all this money. It can learn and upgrade their system by analyzing the user inputs. Therefore, you can reduce the cost factor significantly. In addition to all that, there are a lot of readymade Chatbot solutions available in the market as well.
The user can utilize those services, and he/she can enjoy its benefits. Therefore, people are starting to move towards Chatbots instead of mobile apps in recent times. You should also start preparing yourself for the future. It will help you to become standout from the rest, for sure.
Conclusion
Nowadays, when there is a lot of demand for Chatbot as well as Mobile Apps, it becomes essential for all of you to be aware of the best option for your business.
Taking this idea into consideration, we have decided to write this blog. Here, we have provided you with the reasons which will help you to analyze the Chatbots vs. Mobile Apps comparison.
We hope you had a great time reading this article. If you’ve any questions or suggestions related to this blog, then feel free to ask them in the comment section. Thank You.!
Šime posts regular content for web developers on webplatform.news.
In this week’s roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.
Using plain text fields for date input
Keyboard users prefer regular text fields over complex date pickers, and voice users are frustrated by the native control ().
Previously, I have relied on plain text inputs as date fields with custom validation for the site, typically using the same logic on the client and the server. For known dates?—?birthdays, holidays, anniversaries, etc.?—?it has tested well.
Stencil is a “web component compiler” that can be used to pre-render web components (including Shadow DOM) or hide them until they are fully styled to avoid the flash of unstyled content (FOUC).
This tool also makes sure that polyfills are only loaded when needed, and its Component API includes useful decorators and hooks that make writing web components easier (e.g., the Prop decorator handles changes to attributes).
import { Component, Prop, h } from "@stencil/core";
@Component({
tag: "my-component"
})
export class MyComponent {
@Prop() age: number = 0;
render() {
return <div>I am {this.age} years old</div>;
}
}
When the CSS display: list-item declaration is applied to an element, the element generates a marker box containing a marker, e.g., a list bullet (the
and elements have markers by default).
Markers can be styled via the ::marker pseudo-element (useful for changing the color or font of the marker), but this CSS feature is currently only supported in Firefox.
I’m assuming most of you have already heard about Gatsby, and at least loosely know that it’s basically a static site generator for React sites. It generally runs like this:
Data Sources ? Pull data from anywhere.
Build ? Generate your website with React and GraphQL.
Deploy ? Send the site to any static site host.
What this typically means is that you can get your data from any recognizable data source — CMS, markdown, file systems and databases, to name a few — manage the data through GraphQL to build your website, and finally deploy your website to any static web host (such as Netlify or Zeit).
In this article, we are concerned with the build process, which is powered by GraphQL. This is the part where your data is managed. Unlike traditional REST APIs where you often need to send anonymous data to test your endpoints, GraphQL consolidates your APIs into a self-documenting IDE. Using this IDE, you can perform GraphQL operations such as queries, mutations, and subscriptions, as well as view your GraphQL schema, and documentation.
GraphQL has an IDE built right into it, but what if we want something a little more powerful? That’s where GraphQL Playground comes in and we’re going to walk through the steps to switch from the default over to GraphQL Playground so that it works with Gatsby.
GraphiQL and GraphQL Playground
GraphiQL is GraphQL’s default IDE for exploring GraphQL operations, but you could switch to something else, like GraphQL Playground. Both have their advantages. For example, GraphQL Playground is essentially a wrapper over GraphiQL but includes additional features such as:
Interactive, multi-column schema documentation
Automatic schema reloading
Support for GraphQL Subscriptions
Query history
Configuration of HTTP headers
Tabs
Extensibility (themes, etc.)
Choosing either GraphQL Playground or GraphiQL most likely depends on whether you need to use those additional features. There’s no strict rule that will make you write better GraphQL operations, or build a better website or app.
This post isn’t meant to sway you toward one versus the other. We’re looking at GraphQL Playground in this post specifically because it’s not the default IDE and there may be use cases where you need the additional features it provides and needs to set things up to work with Gatsby. So, let’s dig in and set up a new Gatsby project from scratch. We’ll integrate GraphQL Playground and configure it for the project.
Setting up a Gatsby Project
To set up a new Gatsby project, we first need to install the gatsby-cli. This will give us Gatsby-specific commands we can use in the Terminal.
npm install -g gatsby-cli
Now, let’s set up a new site. I’ve decided to call this example “gatsby-playground” but you can name it whatever you’d like.
gatsby new gatsby-playground
Let’s navigate to the directory where it was installed.
cd gatsby-playground
And, finally, flip on our development server.
gatsby develop
Head over to http://localhost:8000 in the browser for the opening page of the project. Your Gatsby GraphQL operations are going to be located at http://localhost:8000/___graphql.
At this point, I think it’s worth calling out that there is a desktop app for GraphQL Playground. You could just access your Gatsby GraphQL operations with the URL Endpoint localhost:8000/___graphql without going any further with this article. But, we want to get our hands dirty and have some fun under the hood!
Gatsby’s Environmental Variables
Still around? Cool. Moving on.
Since we’re not going to be relying on the desktop app, we’ll need to do a little bit of Environmental Variable setup.
Environmental Variables are variables used specifically to customize the behavior of a website in different environments. These environments could be when the website is in active development, or perhaps when it is live in production and available for the world to see. We can have as many environments as we want, and define different Environmental Variables for each of the environments.
Gatsby supports two environments: development and production. To set a development environmental variable, we need to have a .env.development file at the root of the project. Same sort of deal for production, but it’s .env.production.
To swap out both environments, we’ll need to set an environment variable in a cross-platform compatible way. Let’s create a .env.development file at the root of the project. Here, we set a key/value pair for our variables. The key will be GATSBY_GRAPHQL_IDE, and the value will be playground, like so:
GATSBY_GRAPHQL_IDE=playground
Accessing Environment Variables in JavaScript
In Gatsby, our Environmental Variables are only available at build time, or when Node.JS is running (what we’ll call run time). Since the variables are loaded client-side at build time, we need to use them dynamically at run time. It is important that we restart our server or rebuild our website every time we modify any of these variables.
To load our environmental variables into our project, we need to install a package:
The develop script instructs the env-cmd package to load environmental variables from a custom environmental variable file (.env.development in this case), and if it can’t find it, fallback to .env (if you have one, so if you see the need to, create a .env file at the root of your project with the same content as .env.development).
And that’s it! But, hey, remember to restart the server since we change the variable.
yarn start // npm run develop
If you refresh the http://localhost:8000/___graphql in the browser, you should now see GraphQL playground. Cool? Cool!
And that’s how we get GraphQL Playground to work with Gatsby!
So that’s how we get from GraphQL’s default GraphiQL IDE to GraphQL Playground. Like we covered earlier, the decision of whether or not to make the switch at all comes down to whether the additional features offered in GraphQL Playground are required for your project. Again, we’re basically working with a GraphiQL wrapper that piles on more features.
Resources
Here are some additional articles around the web to get you started with Gatsby and more familiar with GraphiQL, GraphQL Playground, and Environment Variables.
The irony of web performance is that the average page weight of a site continues to go up year after year, despite us being more aware of the problem and having more tools at our disposal to fight it than ever.
To paraphrase Seinfeld, “we know how to fight page weight issues; we just don’t use the tools we have to fight page weight issues.”
That’s why Jetpack provides powerful features for all users at any plan level. They made it so that performance is integrated right into managing content on a WordPress site.
One of those things is lazy loading images. Lazy loading is an excellent technique to defer loading images until they are actually needed. So, an image never loads until the user actually scrolls to where it comes into display. That could potentially save a ton of server requests and precious bytes when waiting for a page to load. Jetpack includes lazy loading, even on free plans, so everyone has access to this performance boost.
And what’s the point of lazy loading anything if you don’t have somewhere to host the files? Well, Jetpack also offers unlimited static file and image hosting for every plan level. No more wondering how much storage is left on your server! You get an unlimited amount of space to store anything you need. That’s pretty awesome!
It gets even more awesome. That’s because the unlimited storage is part of a CDN that is designed to serve images from high-speed dedicated data centers that make downloads as fast and smooth as possible. Again, that’s free to everyone!
That makes Jetpack a super resource for combatting performance issues on a WordPress site. Hey, we use Jetpack here at CSS-Tricks and it’s a linchpin for so much of how this site works and operates. The performance benefits are a nice perk but it’s worth checking out everything it has to offer because there’s likely so much more you can leverage.
Any time I start working on a new project, I ask myself, “Should I use separate git repositories for my back-end server and my front-end client(s)? What’s the best way to organize the codebase?”
I had this same question after a few months working on my personal website. I originally had all the code in the same repository: the back end used Node.js and the front end used ES6 with Pug. I adopted this organization for convenience, since having both projects in the same repo made it easy to search for functions and classes, and facilitated refactors. However, I found some downsides:
No independent deployments.
Both apps were using the same package.json, and there was no clear separation on both projects.
Unclear boundaries.
Since I rely on a global package.json, I didn’t have a mechanism to set specific versions for the back end and front end.
Shared utilities and code without versioning.
After some research, I found that Yarn workspaces was a great tool to solve those cons, and it was a helpful tool to create a monorepo project (more to come later!).
In this article, I share an intro to Yarn workspaces. We’ll run through a tutorial together on how to create your first project with it, and we’ll finish with a recap and next steps.
What Are Yarn Workspaces?
Yarn is a package manager by the folks at Facebook, and it has a great feature called Yarn workspaces. Yarn workspaces let you organize your project codebase using a monolithic repository (monorepo). The idea is that a single repository would contain multiple packages. Packages are isolated and could live independent of the larger project.
As an alternative, we could place all of these packages into separate repositories. Unfortunately, this approach affects the shareability, efficiency, and developer experience when developing on the packages and their dependent projects. Furthermore, when we work in a single repository we can move more swiftly and build more specific tooling to improve processes for the entire development life cycle.
React is a good example of an open-source project that is monorepo. Also, React uses Yarn workspaces to achieve that purpose. In the next section we will learn how to create our first monorepo project with Yarn.
Creating A Monorepo Project With React And Express Using Yarn Workspaces In Six Steps
So far, we have learned what Yarn is, what a monorepo is, and why Yarn is a great tool to create a monorepo. Now let’s learn from scratch how to set up a new project using Yarn workspaces. To follow along, you’ll need a working environment with an up-to-date npm install. Download the source code.
Prerequisites
To fully complete this tutorial, you will need to have Yarn installed on your machine. If you haven’t installed Yarn before, please follow these instructions.
These are the steps we’ll be following in this tutorial:
In your local machine terminal, create a new folder called example-monorepo:
$ mkdir example-monorepo
Inside the folder, create a new package.json with our root workspace.
$ cd example-monorepo
$ touch package.json
This package should be private in order to prevent accidentally publishing the root workspace. Add the following code to your new package.json file to make the package private:
2. Create A React Project And Add It To The Workspace List
In this step, we will create a new React project and add it to the list of packages inside the root workspace.
First, let’s create a folder called packages where we will add the different projects we will create in the tutorial:
$ mkdir packages
Facebook has a command to create new React projects: create-react-app. We’ll use it to create a new React app with all the required configuration and scripts. We are creating this new project with the name “client” inside the packages folder that we created in step 1.
$ yarn create react-app packages/client
Once we have created our new React project, we need to tell Yarn to treat that project as a workspace. To do that, we simply need to add “client” (the name we used earlier) inside the “workspaces” list in the root package.json. Be sure to use the same name you used when running the create-react-app command.
Note: This tutorial is simplified with only two packages (server and client). In a project, you might typically have as many packages as you need, and by convention the open-source community use this naming pattern:@your-project-name/package-name. For example: I use@ferreiro/serveron my website.
4. Install All The Dependencies And Say Hello To yarn.lock
Once we have added our React app, as well as our Express server, we need to install all the dependencies. Yarn workspaces simplifies this process and we no longer need to go to every single application and install their dependencies manually. Instead, we execute one command — yarn install — and Yarn does the magic to install all the dependencies for every package, and optimize and cache them.
Run the following command:
$ yarn install
This command generates a yarn.lock file (similar to this example). It contains all the dependencies for your project, as well as the version numbers for each dependency. Yarn generates this file automatically, and you should not modify it.
5. Using A Wildcard (*) To Import All Your Packages
Until now, for every new package we have added, we were forced to also update the root package.json to include the new package to the workspaces:[] list.
We can avoid this manual step using a wildcard (*) that tells Yarn to include all the packages inside the packages folder.
Inside the root package.json, update the file content with the following line: "workspaces": ["packages/*"]
Last step! We need to have a way to run both packages — the React client and the Express client — simultaneously. For this example, we will use concurrently. This package let us run multiple commands in parallel.
Add concurrently to the root package.json:
$ yarn add -W concurrently
Add three new scripts inside the root workspace package.json. Two scripts initialize the React and Express clients independently; the other one uses concurrently to run both scripts in parallel. See this code for reference.
Note: We will not need to write ourstartscripts into the “server” and “client” packages because the tools we used to generate those packages (create-react-appandexpress-generator) already add those scripts for us. So we are good to go!
Finally, make sure you update the Express boot-up script to run the Express server on port 4000. Otherwise, the client and server will try to use the same port (3000).
var port = normalizePort(process.env.PORT || '4000');
Now we are ready to run our packages!
$ yarn start
Where To Go From Here
Let’s recap what we’ve covered. First, we learned about Yarn workspaces and why it’s a great tool to create a monorepo project. Then, we created our first JavaScript monorepo project using Yarn, and we divided the logic of our app into multiple packages: client and server. Also, we created our first basic npm scripts and added the required dependencies for each app.
From this point, I’d suggest you review open-source projects in detail to see how they use Yarn workspaces to split the project logic into many packages. React is a good one.
Also, if you want to see a production website using this approach to separate back-end and front-end apps into independent packages, you can check the source of my website, that also includes a blog admin. When I migrated the codebase to use Yarn workspaces, I created a pull request with Kyle Wetch.
Moreover, I set up the infrastructure for a hackathon project that uses React, webpack, Node.js, and Yarn workspaces, and you can check the source code over here.
Finally, it would be really interesting for you to learn how to publish your independent packages to become familiar with the development life cycle. There are a couple of tutorials that are interesting to check: yarn publish or npm publish.
For any comments or questions, don’t hesitate to reach out to me on Twitter. Also, in the following months, I’ll publish more content about this in my blog, so you can subscribe there as well. Happy coding!