Google has been serving the search community much better of late. Whether it is about announcing the latest updates, posting useful documentation or answering questions asked to the members of the team, Google is really quick stating what works and what doesn’t work in searches. There are some SEO techniques that Google does not support officially but are still effective and useful, to some extent.
One of these for websites built using AJAX based dynamic content is the escaped fragment solution with which content can be made easily accessible to search engine bots. The method involves using a hashbang (#!) to specify the parameter that allows the search engine to rewrite the URL and request content from a static page. Google has announced the deprecation of this solution and no longer supports it but it is still effective and not killed off.
In this guide, we talk about how you can use hash bang URLs for SEO.
Hashbang SEO in 2019 – What You Should Know?
A hash URL is when you click on a link and it jumps to a particular section of the page. Using a link in the meta description is a great way to rank on the search engine. When writing content, it is not always possible to answer the user’s question in a way that they can find it instantly. Creating hash URLs and allowing Google to jump to the content of interest right from the meta description means they are more likely to stay on the page.
Javascript and Ajax can use a hash method to create HTML snapshots for single page applications. When something is clicked, the content is reloaded but the base URL remains the same. Google mentioned that adding exclamation mark next to the hash in an URL can make the AJAX pages visible to Google. But, the search engines generally ignore the URL parameters after the hash.
Google announced in 2015 that the AJAX crawling scheme is deprecated and no hashtags should be used in URLs as they are bad for the search. However, this was about the use of hashtags where it called new content to be loaded. Using them as basic web anchors to scroll to a particular section of the page that was already loaded at the first load is completely fine. If you program the site to load new content based on what comes after the hash sign in the URL, it is not supported. Google made clear in 2017 that Ajax pages using hashbang URLs will be rendered.
It has also provided a syntax for working with the fragments. The hash bang syntax suggests placing an exclamation mark next to the hash sign to tell Google that you used the fragments for loading separate variations of the content that you want to be crawled. With this approach, your pages with hash bang URLs will be crawled, seen and indexed by Google and will benefit your SEO.
Hashbang URLs
An URL that contains a hashtag # character is a hash URL. The part of the address to the left of the # represents a resource downloadable by the browser and the portion to the right, called the fragment identifier, represents a location within the resource. The browser tries to find the anchor tag with an id attribute corresponding to the fragment and scrolls the page in real time to display the section. Google proposed the use of hashbangs for single page application rendering in 2009. The proposal was for pages where the content is determined by a fragment identifier and JavaScript was accessible by adding the base URL with query parameter. Use of hashbang URLs indicates that the webpage uses client-side rendering to deliver the right content.
A large number of sites use hashbang URLs as they have some useful features which make them great for client-side applications. Apart from providing addresses for application states, giving caching, enabling web applications to fetch data from other servers, hashbang URLs have SEO benefits as well. Use of hashbang URLs increases the rank of the page for the base URL. This is because in a search engine, more links would point to the base URL.
Remove Hashbang Angular
Angular is a development framework created and maintained by Google. It is loaded with features like Dependency Injection, Two Way Binding, Directives and Testing. This framework is used extensively to create Single Page Applications. Whenever you use Angular JS and write the URL, it adds a hashtag at the end of the application root folder. This happens because Angular is a javascript framework working at the front-end rather than back-end and a hashtag is added by default.
For example,
Removing these hashtags from the URL to get clean URLs is easy. It can be done by adding two things.
- Configuration of $locationProvider
- Setting the base path for relative links
The $location service is responsible for parsing the URL in the address bar and makes the URL available to the application. Any modifications made to the URL in the address bar affect the service and changes made to the $location affect the URL in the browser’s address bar. We can use the #locationProvider module and html5Mode to remove the hashbang. You can write
$locationProvider.html5Mode (true);
to configure the module and change the URL.
Next, we can set the base URL in the application by writing the <base> tag in the head section of the HTML. This ensures that the application loads correctly.
We hope you find this guide helpful. Do share your thoughts and experiences with us in the comments section below.