惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Visual Studio Blog
O
OpenAI News
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
Project Zero
Project Zero
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
G
Google Developers Blog

Bryan Robinson's Blog

Does our technology still work for us? Product pricing, dev bad habits, and the role of the pit of success Astro Server Island for latest Bluesky post (heavily cached!) Type-safe environment variables in Astro 5.0 New Website, but really is it? Netlify Durable Cache: Caching for a third-party world Introducing the Hygraph Astro Content Loader Integrating Astro.js Starlight Documentation into a Next.js Project Using Proxies Jamstack is meaningless 😱 Book Release: Eleventy by Example – Learn 11ty with 5 in-depth projects 11ty Second 11ty: Creating Template Filters 11ty Second 11ty: Global Data files (JS and JSON) 11ty second 11ty: The Render Plugin Part 1 Help needed: Netlify Frontend environment variables with Astro.js Quick experiment with the Slinkity 11ty plugin Creating a dynamic color converter with 11ty Serverless Using 11ty JavaScript Data files to mix Markdown and CMS content into one collection How to show your template code in 11ty blog posts New City, New Job, New Content Using Nunjucks Climbing the 11ty Performance leaderboard with Cloudinary, critical CSS and more Three JAMstack movements to watch in 2020 Create a Codepen promo watermark with no additional HTML, CSS or JS 3 underused CSS features to learn for 2020 Use CSS Subgrid to layout full-width content stripes in an article template Adapt client-side JavaScript for use in 11ty (Eleventy) data files CSS Gap creates a bright future for margins in Flex as well as Grid Create your first CSS Custom Properties (Variables) Use CSS Grid to create a self-centering full-width element Creating an 11ty Plugin - SVG Embed Tool Now offering design and code reviews at PeerReviews.dev Routing contact-form emails to different addresses with Netlify, Zapier and SendGrid Create an Eleventy (11ty) theme based on a free HTML template Client work and the JAMstack Grid vs. Flex: A Tale of a "Simple" Promo Space Using Eleventy The Tech Barrier to Entry What Can We Learn from CERN Let Practical CSS Grid - Launching My First Course Build Trust on the Web incorporating User Worries with your User Stories Refactoring CSS into a Sass mixin Starting a new journey with Code Contemporary Dynamic Static Sites with Netlify and iOS Shortcuts Top 3 uses for the ::before and ::after CSS pseudo elements How To: Use CSS Grid to Mix and Match Design Patterns Use CSS ::before and ::after for simple, spicy image overlays Modern CSS: Four Things Every Developer and Designer Should Know About CSS 3 Strategies for Getting Started with CSS Grid CSS Tip: Use rotate() and skew() together to introduce some clean punk rock to your CSS The 5 Stages of Grid Love How To: A CSS-Only Mobile Off Canvas Navigation How To: Use CSS Grid Layout to Make a Simple, Fluid Card Grid Make a More Flexible Cover Screen with CSS Grid Can CSS Grid open up interesting CMS Layout options? Firefox 52 to Introduce New Box-Alignment Values Falling Forward — Rethinking Progressive Enhancement, Graceful Degradation and Developer Morality Start Exploring the Magic of CSS Grid Layout I Converted My Blog to CSS Grid Layout and Regret Nothing Feature Queries are on the Rise CSS Shapes — Let the Text Flow Around You Flexbox -- Let Memorializing Prince and Print vs. The Web I went to Italy and noticed UX fails How to Get Designers to Contribute in Open Source The True Gift of Your Former Code
2019 The Year of Markup-First Development
2018-12-19 · via Bryan Robinson's Blog

Year of Markup Graphic

All right, everyone. I’m calling it. 2019 will be the year of “Markup-first development.” Not because we want it to be, but because we need it to be.

The state of the web in 2018 has been heavy into the world of JavaScript. We’ve made amazing advancements in the way our sites work. Every site has the ability to feel like an application. Smooth, fast transitions happen between states and pages. It definitely feels like the future of the web.

Without HTML, though, our fancy future may have a dystopian layer right beneath the surface.

Why worry about the fate of HTML?

HTML is a simple authoring language. It’s declarative, descriptive and easily analyzed. It fits nicely in the “Rule of Least Power” as described by Tim Berners-Lee.

Let’s break the importance of that down a little more.

HTML is Declarative

A declarative language is easy to understand. HTML was created to be an authoring language for content. 

It’s structure is built in a way that non-technologists can learn quickly. I’ve taught HTML to college students and to 60-year old journalists. Across the board, it’s never taken more than an hour to pass on the knowledge they need to create simple content.

Because of it’s declarative nature, not only do humans author it easily, but machines can as well. There are dozens of WYSIWYG editors available that can create viable markup. That’s not to say that machines can’t author JavaScript. At the end of the day, though, it requires very little power and logic to create HTML from simple rules.

HTML is Descriptive

HTML means what it says, by default. With no CSS and no JS, your page has additional meaning outside of your content. 

With no effort outside of your authoring, you are able to describe each piece of your content with important information. A paragraph is semantically a paragraph. An image is an image. 

HTML can be easily analyzed

Because of its descriptive nature and simple declarative style, HTML is easy for any system to analyze. All of the information is matched together with the data about the information. It can be read by a system and remixed. 

It can be used by a browser, by a screen reader or by a bot.

If anything happens to its declarative and descriptive nature, it becomes much harder to analyze. This can have potentially crippling affects on your site and your users.

If a bot can’t easily scrape your site, your search rankings will go down. If a screen reader doesn’t understand your markup, a user won’t be able to access your content. Write your content in something a browser doesn’t understand and no one with that browser can access it.

So, why is it that more and more apps and websites look like this:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>My Awesome SPA site</title>
</head>
<body>
    <div id="app"></div>
</body>
</html>

I think the simple answer is that we get a lot of power from new methods and don’t want to have to think about old methods. That’s a simplistic take, but it’s not far from the mark.

So, how do we fix this epidemic in 2019?

Write and think “Markup First”

Developers need to take a step back when writing the code for their application. They need to think and write in a markup-first mind set.

How can you do this with minimal effort (because let’s face the facts, humans are lazy)? 

Here are my two simple steps to shipping accessible, analyzable, semantic code.

Step 1: Put the HTML back in your HTML document

Shipping an HTML document with no content to the browser and praying to your JavaScript to finish the job is not a sound strategy.

Let’s examine some potential issues:

  • A screen reader doesn’t understand your JS
  • A bot doesn’t understand your JS
  • Your JS doesn’t get downloaded due to network issues
  • A user opts out of your JS (hey, it happens)

These aren’t all the scenarios, but any of them can come up at any time. The more they happen, the more angry users you’ll have not being able to consume your app.

Let’s talk about two strategies for shipping real HTML.

First, there’s the old standby: write your HTML and have your app replace it with JavaScript.

Most modern JavaScript frameworks want a single root element to completely overwrite. Might as well use that to your advantage.

Write your HTML inside of that element and then let the JS take it from there.

This method works well for small applications. As soon as you have more than a handful of states or routes, it becomes much more difficult to manage. You need an individual HTTP route for each of your JS routes.

That’s where prerendering comes in.

The “simple” solution to pre-rendering is to use a third party. Prerender.io is a popular service that you can integrate with that will build and store static HTML for your app. It becomes a dependency of your code and you have API access to its functionality. 

Prerender is a third-party software as a service product. You may not want to pay a company to do this for you.

That’s OK. There are other methods, as well.

One of the biggest trends in 2018 has been the resurgence of static hosting. You store your static HTML on a cheap, secure and lightning fast service. Since much of what we work with in front-end development doesn’t require server-side code, we can use a service like Netlify or Surge.sh to host.

This gives us easy access to use our build process to create what we need for rendering HTML alongside our JS.

The great thing about this is that there are frameworks that do a lot of the heavy lifting for you.

Are you a React lover? Check out Gatsby. Prefer Vue? NuxtJS is where you want to look. 

These are amazing because the complexity is in the build. This means that you get the developer convenience of writing your application once with tools you enjoy and the user gets all the benefits of server rendering AND SPA-style pages.

Step 2: Think about your markup

It’s not enough to just render HTML in your HTML document. It also needs to be well constructed.

If you’re not accustomed to thinking about your HTML, it might come as a shock that there’s a lot of thought that’s been put into each element.

Let’s look at the case of a clickable element. What HTML element should you use to make something clickable?

Let’s get this out of the way first. Although you can write this code and have it work, don’t do this:


<span onclick="runFunction();">Click me!</span>

Full stop. Don’t do it. I feel like this shouldn’t have to be said, but I’ve seen it too much in the wild…

If you answered an anchor tag, you MIGHT be right, but only in some cases. I can’t do the subject justice like Ire Aderinokun in her post “Anchors vs. Buttons.” Read the entire post, but here’s a quick quote on anchors and buttons.

The <a> element represents a hyperlink to a destination page or a section within a page. The element is labelled by its contents, which can be anything from an image to additional (non-interactive) elements like <div>s, <p>s, etc. ... The <button> element, more specifically the <button type=“button”> element, does nothing.

She goes on to describe additional differences between the elements. Screen readers will read them differently and keyboard users interact with them differently.

Her post really highlights how much thought can go into even the simplest choice.

If you’re not willing to put the same thought into your markup as you are into your JavaScript, you’re doing a disservice to your user.

Accessibility is immensely important. I can’t underscore that enough. If you’re not willing to think about your markup’s semantics for that, think about SEO value.

I mentioned in the intro that HTML is descriptive and that the descriptiveness makes it analyzable. So, what happens if you describe things poorly? It’s still analyzable, but the analysis will be wrong. A bot reading your content will prioritize the wrong things.

Imagine a blog post written like this:


  <div class="article">  
      <div class="big-header">Headline for my story</div>  
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut volutpat lorem dolor. Aliquam volutpat aliquet sollicitudin. Praesent venenatis pulvinar mi, vel elementum neque fringilla eu. Cras sodales neque vel ultricies condimentum. Duis a ante id felis egestas bibendum at vitae justo.</p>  
      <div class="secondary-header">Section headline for my story</div>  
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut volutpat lorem dolor. Aliquam volutpat aliquet sollicitudin. Praesent venenatis pulvinar mi, vel elementum neque fringilla eu. Cras sodales neque vel ultricies condimentum. Duis a ante id felis egestas bibendum at vitae justo.</p>  
  </div>

This may seem like a strawman argument, but I’ve seen instances of  this too often.

The problem with the code above is that bots have no way of structuring importance of those elements. In fact, the paragraphs will have a higher value in a bot’s eye than our headlines.

When writing content, I pay close attention to the various headline levels. This adds the right metadata to my content. It makes it something that bots will enjoy analyzing. If you’re working on personal projects, it might not matter. I can almost guarantee your client or your boss (or boss’s boss) will care.

Hand-in-hand with semantics is your structure. HTML is infinitely nestable. Just because you CAN do something doesn’t necessarily mean you should.

Often nesting in HTML is a symptom of styling. To accomplish a design set before of, sometimes we suffer from divitis

This is changing with modern CSS, but it requires a mental shift. The same goes for JavaScript. Sometimes that extra level has been mandatory in the past.

Due to limitations in the way React rendered the DOM, if you wanted to render multiple sibling components, you would have to wrap them in an arbitrary parent.

This is less than ideal for clean markup. In React v16.0, the React team released the concept of Fragments. This allows for a developer to have multiple elements rendered at the top level of a component.

I love the example that the React docs use for this use case. In the example, they have <tr> that has a single component <Columns /> inside. The <Columns /> Component has two <td>s inside of it. In the old way those would be wrapped in a <div> or <span> which is not valid HTML. By wrapping it in a <React.Fragment> tag, it will instead render just the two <td>

This keeps you structure much closer to its semantic needs. This will help bots and screen readers, but I also find it helps your future self.

If you open up developer tools to inspect elements, the deeper things are nested the harder they are to debug. Save yourself the hassle and keep nesting simple.

Elements that describe a single group of information should be grouped. Your HTML should read like a well-written article.

Complete thoughts are grouped into sentences. Complete concepts are grouped into paragraphs. Complete points are grouped into sections. Sections are grouped into your story.

HTML should be readable by anyone coming after you. It should be logical, clean and precise.

Additional Perks

If you’re looking for more reasons to adopt this line of thinking, ponder this. 

There have been lots of movements telling you what to think or write first. Mobile first. Resilient design. Support first.

If you take the time to structure your semantically correct markup properly, you get all of that out of the box. Everything we need the web to be in the future, stems from good HTML.

Final Thoughts: Please think

In 2019, as the JavaScript ecosystem continues to build it’s momentum, please don’t neglect the foundation of the web.

The better the HTML of our sites and applications, the better the entire web will be.

Just like you plan out your application, you should plan out how your application will render. Think about the order, the semantics, the structure and the users be they bots, browsers, screen readers or humans.

Happy New Year!