问题原文
原帖链接 · 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:
Using CSS
display: none & display: blockto show the content based on filter and,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:
https://developers.google.com/search/docs/advanced/javascript/dynamic-rendering
https://developers.google.com/search/docs/advanced/javascript/javascript-seo-basics
https://stackoverflow.com/questions/4536626/javascript-isnt-good-for-seo-is-it
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
