React.js与MVC ASP.NET TTFB加载.jsx需要太长时间

时间:2022-10-19 21:36:17

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.

我已经将React.js与我的asp.net MVC应用程序集成在一起。主要是当我在本地调试或者我连续进入网站时它加载得足够快,这是我假设由于缓存。

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

当我第一次进入我的网站后,就像让我们说的那样,半小时.jsx文件花了很长时间

The time and the values:
React.js与MVC ASP.NET TTFB加载.jsx需要太长时间

时间和价值观:

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.

花了32秒!我希望这不正常,也不是那么大的文件。它只有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.

现在我对React.js很新,我想知道我做错了什么,或者由于服务器速度慢而发生这种情况,我没有最好的服务器,但是这台服务器上的其他网站都不在此处慢。

Thanks in advance.

提前致谢。

1 个解决方案

#1


0  

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

显然你可以在MVC项目中预加载脚本。在App_Start> ReactConfig.cs中,在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.

正如您所看到的,我正在使用我的Home.jsx中也需要的gapi和firebase脚本,但问题是我无法从Home.jsx到达这些脚本中的函数,所以这一切都开始慢慢让我疯狂。

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.

我作为一个解决方案所做的只是放弃尝试在asp.net MVC中使用Reactjs并制作一个单独的适当的reactjs应用程序,我使用C#作为Web服务。现在我没有加载时间问题,它像闪电一样加载。

#1


0  

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

显然你可以在MVC项目中预加载脚本。在App_Start> ReactConfig.cs中,在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.

正如您所看到的,我正在使用我的Home.jsx中也需要的gapi和firebase脚本,但问题是我无法从Home.jsx到达这些脚本中的函数,所以这一切都开始慢慢让我疯狂。

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.

我作为一个解决方案所做的只是放弃尝试在asp.net MVC中使用Reactjs并制作一个单独的适当的reactjs应用程序,我使用C#作为Web服务。现在我没有加载时间问题,它像闪电一样加载。