简体   繁体   中英

React.js with MVC ASP.NET TTFB loading of .jsx takes too long

I have integrated React.js with my asp.net MVC application. The main thing is it loads fast enough when I am debugging locally or when I am entering the website consecutively, which is I assume due to caching.

But

when I am entering my website for the first time after like let's say, half an hour the .jsx file takes a crazy long time

The time and the values:
您可以在此处查看时间和值

It took 32 s! I hope that's not normal and it's not that big of a file either. It's only 17.6 KB .

Now I am pretty new to React.js , I am wondering what I have done wrong or could this be happening due to a slow server, I don't have the best server at my disposal but other websites on this server are nowhere near this slow.

Thanks in advance.

So apparently you can preload scripts in MVC projects. Right inside App_Start > ReactConfig.cs and add the following line inside Configure():

ReactSiteConfiguration.Configuration = new ReactSiteConfiguration().AddScript("~/Scripts/gapi.js").AddScript("~/Scripts/firebase.js").AddScript("~/Scripts/React/Home.jsx");

As you can see I am using gapi and firebase scripts which were also required in my Home.jsx, but the problem is I cannot reach the functions inside these scripts from Home.jsx so this all started to slowly drive me insane.

What I did as a solution was simply give up trying to use Reactjs inside asp.net MVC and made a separate proper reactjs application and I am using C# as a web service. Now I am having no loading time problems, it loads like lightning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM