Intelligent Ajax Deep Linking for search engines so that Meta data is loaded in HTML instead of DOM

久未见 提交于 2020-01-17 02:39:12

问题


I'm searching for a good way of deep linking together with different meta tags. Currently I have a huge main HTML site and showing the subpages via JavaScript and DOM manipulations.

Let's take my latest project as example (Google Search). There you can see that the meta tags (let's take just the description for simplification) are always the same. But in the DOM I changed it as you can see on the site. But I know Search Engine just take the HTML code and having JS mostly disabled. Here the lines in the JavaScript code that I used to change title, description and keywords.

Example

    $('meta[name=keywords]').attr('content', 'ages,third');
    $('meta[name=description]').attr('content', 'The Third age is where The Hobbit and Lord of the Rings take part.');
    document.title = "Third Age - Arda Maps"; 

As you can see from the Google search, the title is properly changed, even tho it is done via JavaScript.

So the question is, if there is a way to also change other meta tags like the description via JavaScript in a proper way?

Note #1: I don't want to use PHP. I know PHP would make it way easier via templating.

Note #2: I also know I could just load the different pages via Ajax. But then I would have to mirror them. And as you can see the main html is very big. Mirroring would in this way be contra-productive. Isn't it?


回答1:


So the question is, if there is a way to also change other meta tags like the description via JavaScript in a proper way?

See Making AJAX Applications Crawlable


open for anything except PHP solutions.

See DCMI Metadata Terms , Expressing Dublin Core metadata using HTML/XHTML meta and link elements

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head profile="http://dublincore.org/documents/2008/08/04/dc-html/">
    <title>title</title>
    <link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
    <meta name="DC.subject" content="subject1, subject2" />
    <meta name="DC.title" content="title" />
    <meta name="DC.description" content="description" />
  </head>
  <body>
  </body>
</html>



回答2:


There is no way to edit the meta tags on a Single-Page web application easily for different pages. The only way is via PHP or Node.js to change it on server-side.

Chaning it on client-side it will just change the DOM what is good for the user as he can see the changes. But search engine will ignore that. Also with the Dublin Core it will not work. Even tho it is designed for just this.

So currently this is not possible.



来源:https://stackoverflow.com/questions/30378184/intelligent-ajax-deep-linking-for-search-engines-so-that-meta-data-is-loaded-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!