Does react framework based website hides code in browser at client side?

我是研究僧i 提交于 2021-02-11 07:02:43

问题


My web developer telling me that react framework based website hides code at the client side. I have website where seeing the source code displays only few line of code nothing else like the body of the website page. Please help. You can find the website at https://raybaby.us/

Any help will be appreciated as I'm struggling with source code regarding SEO of website.


回答1:


From the context of your question - I think what you're referring to is the rendering of the HTML.

So yes typically what happens on a frontend-only react app is you will have an html file that looks like this:

<html> 
   <head> 
      <!-- some meta information here, perhaps a base css style--> 
   </head> 

   <body>  
      <div id = "root">
           <!-- this element is left empty, 
               and then react will use javascript to populate it
           --> 
      </div> 
      <script src=...> <!-- the react script--> </script> 
   </body> 
</html>

And then what happens is that the page loads, then the javascript runs, and manipulates the dom and populates it with your content.

From an SEO perspective, (and I certainly don't have any indepth experience with SEO), my understanding is that once upon of time this would have been a bad thing, because the web crawlers wouldn't run the Javascript - they'd see the empty HTML only.

However, my understanding is that this is no longer the case.

However - if you do want content to be rendered without have the javascript run - you can use server side rendering. What SSR will do is use React to render static HTML on the backend, providing the pre-existing HTML and CSS boilerplate to exist, before the javascript starts running.

(If you're interested, I've personally found this project a really good template for SSR).

It's up to you to do some research on whether you need this for your SEO, but that's the basics of it.



来源:https://stackoverflow.com/questions/53474656/does-react-framework-based-website-hides-code-in-browser-at-client-side

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