大网数据广告活动
网站运营与故障问答

How JSON works in HTML Script Tag regarding SEO Search availability?

· 52CE 我爱测

I know this topic already all over the forum. But still, I'm confused if there is no exact example of what they mean with dynamic render using Javascript. so here is the background of my question: I want to make a landing page fo…

问题原文

原帖链接 · Rakis Friski · CC BY-SA 4.0

I know this topic already all over the forum. But still, I'm confused if there is no exact example of what they mean with dynamic render using Javascript.

so here is the background of my question:

I want to make a landing page for SEO purpose where the content is about some general question that people usually ask, but there are some feature that I need such as Filter based on question type, is the question itself already answer or not, and question type whether it is math, history, or biology. But for it, There is around 2 technique that I can use to make a dynamic content using HTML, CSS, and Vanilla JS since it can only show 1 category at a time. There are:

  1. Using CSS display: none & display: block to show the content based on filter and,

  2. The other one using JSON data that I already make the exact structured for the content purpose such as this example below, and put it in the script tag for accessing it after append it to a specific div:

[{
 "data": {
  "items": [{
   // around 500 question in here with several variable such as name, questionType, id, etc.
  }]
 }
}]

So, here is my question:

Which Technique that I better use if I want search engine to crawl for dynamic content? CSS hidden technique Which I already render all component but only give display: block for the default value and the other get display: none so its hidden but already in HTML body or using JSON data that I already put in HTML script tag, where I make it show based on parameter that the function send, so the content will be dynamic based on JSON data that match the value without rendering it all in HTML body first so the HTML structure can still be clean without repeating the same div which only the content is different over and over again?

and... this is just my curiosity but, perhaps... when we put JSON directly in script, Is search engine will automatically crawl it?

just for information, this is some article that I already read:

  1. https://developers.google.com/search/docs/advanced/javascript/dynamic-rendering

  2. https://developers.google.com/search/docs/advanced/javascript/javascript-seo-basics

  3. https://stackoverflow.com/questions/4536626/javascript-isnt-good-for-seo-is-it

  4. https://moz.com/blog/javascript-seo-guide

I hope someone can help me regarding this problem, I'm quite confused even after read a lot of article regarding this problem

if you confused about how the data will looks like in code, it will looks like this:

<body>
<div>
  // some content code in my website
  <button onclick="filterData('history')">Filter Data</button>

  <div id="dynamicContent"></div>
</div>

<script>
const datas = [{
 "data": {
  "items": [{
   // around 500 question in here with several variable such as name, questionType, id, etc.
  }]
 }
}]

function filterData(param){
  // function to assign the **datas** and **will append it to div with "dynamicContent" ID**
}
</script>
</body>

已采纳解答

原帖链接 · BNazaruk · CC BY-SA 4.0

You're making a mistake when you talk about JSON in this story. JSON is just a format and it plays exactly no role here. What is more important is JS rendering. Also, you're showing the source of your page. Source is as unimportant as JSON is. Google doesn't index source, it indexes DOM. So show DOM.

Now, as I understood, the real question here is: A user lands on a page with a bunch of query params in it (filters or not is of no importance either). The backend is not smart enough to understand what those parameters mean, so the backend always responds by sending all that it has (which is poor). Now on the front-end, you want to parse the query string with your pure JS and depending on the query params, filter the data displayed, correct?

If that is a correct interpretation, then the answer is: no difference. Google will execute your js and see the results. Just make sure you don't do any lazy loading or wait for user action to render the content. That would complicate things. In your shoes, I would definitely fix my backend to not flood the user with stuff that was never requested. Well, if I only had the two options that you presented, then I would not want to needlessly increase DOM's cardinality and sheer size.

For SEO, it is important to maintain the URL structure of every piece of unique content. So when dynamically hiding/showing content on a page without changing the URL, you should be ready for this content not to be indexed. And when the URL is changing on show/hide, you must make sure that re-visiting the changed url with no context will lead to correct piece of event being visible.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2021-12-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。