• Search Engine Land
  • Sections
    • SEO
    • SEM
    • Local
    • Retail
    • Google
    • Bing
    • Social
    • Resources
    • More
    • Home
  • Follow Us
    • Follow
  • Search Engine Land
  • SEO
  • SEM
  • Local
  • Retail
  • Google
  • Bing
  • Social
  • Resources
  • Live
  • More
  • Events
    • Follow
  • SUBSCRIBE

Search Engine Land

Search Engine Land
  • SEO
  • SEM
  • Local
  • Retail
  • Google
  • Bing
  • Social
  • Resources
  • More
  • Newsletters
  • Home
SEO

The right way to apply JavaScript to your links for SEO

Google’s Martin Splitt explains why fragment identifiers don’t get crawled and the importance of href attributes.

George Nguyen on April 29, 2020 at 2:01 pm
  • More

“Use proper link markup, do not use fragment URLs for links you want crawlers to discover and follow, and you should be building websites that work well with JavaScript and the links will be found,” Martin Splitt, developer advocate at Google, summed up on Google’s Webmaster Conference Lightning Talk Wednesday.

The right way to create links. Using the HTML <a> tag with the destination URL in the href attribute is the most straightforward way to create a link. For example, <a href=”https://example.com”>link</a>.

You can also add JavaScript to a link, allowing you to upgrade its functionality. One example of this might be when a user clicks on a pop-out hamburger menu on one of your pages — the JavaScript could be used to intercept the href and display the hidden hamburger menu.

Don’t leave out the href attribute. It may be tempting to eliminate the href attribute and “clean up” your code, but doing so means that the link will only work if your JavaScript is also functioning properly. Crawlers only access content pointed to with href attributes and if there’s a bug, users can’t access the content the JavaScript is pointing to.

Think twice about fragment identifiers. Fragment identifiers, which are distinguished by a “#” symbol within a URL, point to subsections of a given page, not necessarily a different page. For example, example.com/FAQ#subsection would take the user to a specific point on the page example.com/FAQ.

“Because fragments aren’t meant to point to different content, crawlers ignore them; they just pretend that the fragments don’t exist,” Splitt said. This means that if you build a single-page application with fragment identifiers, crawlers will not follow those links. 

Why we care. Creating links that Google can crawl will help it understand what your site content is about and increase your chances of ranking well for relevant queries. And, while it is not common, some users may choose to browse with JavaScript turned off; when that’s the case, adhering to these practices will ensure that your links still function correctly.

More development tips for SEOs

  • Our SEO for Developers Column
  • Chrome 88 adds to Core Web Vitals DevTools
  • Google's Lighthouse is now recommending JavaScript library alternates
  • How to show Lighthouse Scores in Google Sheets with a custom function


About The Author

George Nguyen
George Nguyen is an editor for Search Engine Land, covering organic search, podcasting and e-commerce. His background is in journalism and content marketing. Prior to entering the industry, he worked as a radio personality, writer, podcast host and public school teacher.

Related Topics

Channel: SEOGoogleGoogle: SEOGoogle: SitelinksSEO - Search Engine OptimizationSEO for DevelopersSEO: Crawling and Robots

We're listening.

Have something to say about this article? Share it with us on Facebook, Twitter or our LinkedIn Group.

Get the daily newsletter search marketers rely on.
See terms.

ATTEND OUR EVENTS

Lorem ipsum doler this is promo text about SMX events.

February 23, 2021: SMX Report

April 13, 2021: SMX Create

May 18-19, 2021: SMX London

June 8-9, 2021: SMX Paris

June 15-16, 2021: SMX Advanced

August 17, 2021: SMX Convert

November 9-10, 2021: SMX Next

October 2021: SMX Advanced Europe

December 17, 2021: SMX Code

Available On-Demand: SMX

×


Learn More About Our SMX Events

Discover actionable tactics that can help you overcome crucial marketing challenges. Our next conference will be held:

MarTech 2021: March 16-17

MarTech 2021: Sept. 14-15

MarTech 2020: Watch On-Demand

×

Attend MarTech - Click Here


Learn More About Our MarTech Events

White Papers

  • A Beginner’s Guide to Omnichannel Marketing using Marketing Automation
  • The Top Five Objections That Hold Companies Back From Doing SEO
  • How To Optimize SEO With UGC
  • Email Tune-Up: A 5-Point Inspection to Get Your Program in Gear
  • Digital Marketing Report Q4 2020: Benchmarks and Insights for 2021
See More Whitepapers

Webinars

  • The Secret Behind SEO Success: Predict Rank with the Power of Data Science
  • How to Avoid the Digital Transformation Trap
  • How to Build a Marketing System of Record
See More Webinars

Research Reports

  • Local Marketing Solutions for Multi-Location Businesses
  • Enterprise Digital Asset Management Platforms
  • Identity Resolution Platforms
  • Customer Data Platforms
  • B2B Marketing Automation Platforms
  • Call Analytics Platforms
See More Research

h
Receive daily search news and analysis.
Search Engine Land
Download the Search Engine Land App on iTunes Download the Search Engine Land App on Google Play

Channels

  • SEO
  • SEM
  • Local
  • Retail
  • Google
  • Bing
  • Social

Our Events

  • SMX
  • MarTech

Resources

  • White Papers
  • Research
  • Webinars
  • Search Marketing Expo
  • MarTech Conference

About

  • About Us
  • Contact
  • Privacy
  • Marketing Opportunities
  • Staff
  • Connect With Us

Follow Us

  • Facebook
  • Twitter
  • LinkedIn
  • Newsletters
  • Instagram
  • RSS
  • Youtube
  • iOS App
  • Google Play

© 2021 Third Door Media, Inc. All rights reserved.

Your privacy means the world to us. We share your personal information only when you give us explicit permission to do so, and confirm we have your permission each time. Learn more by viewing our privacy policy.Ok