如何检查是否加载了部分视图,然后加载javascript [英] how to check if partial view is loaded and then load javascript
问题描述
我对某个问题有疑问。由于我的应用程序使用部分视图和这些部分视图由ajax调用加载,每个部分视图使用javascript并包含js文件,最终调用数据库来绑定该特定视图的数据。现在,加载视图所花费的时间比预期的多,因为它加载了js文件,而js文件再次调用服务器来提取记录。我希望我的视图被加载,然后js文件使db调用绑定数据。如下所示 -
如果(部分视图加载)加载js文件,这将进行ajax调用,db最终将绑定数据。
这将至少加载视图,用户将有东西可以看到而不是等待装载机的空白背景。
请帮帮我找到合适的解决方案。
任何帮助都将不胜感激。
I have a query regarding an issue. As my application using Partial views and these partial views are loaded by ajax call and each partial view usage javascript and include js file, which eventually calls database to bind the data for that particular view. Now, loading the view is taking more time than expected, as it loads js file and that js file makes another call to server to pull the records. I want my view to be loaded and then js file which makes db call to bind data. something like below -
If(partialview is loaded) load js file , which will make ajax call and db eventually to bind data.
This will at least load the view and user will have something to see instead of waiting for blank background with loader.
Please help me to find the proper solution.
Any help will be appreciated.
推荐答案
如果使用太多页面中的脚本文件会阻止页面的呈现。
所以你最好异步加载你的脚本文件。
用于加载你的脚本异步文件,您只需在脚本标记中添加async
:
If you use too many script files in your page it blocks the rendering of the page.
So you better load your script file asynchronously.
for loading your script file asynchronously you just have to addasync
in your script tag :
<script src="yourjsfile.js" async></script>
希望它可以帮到你。
Hope it helps you.
这篇关于如何检查是否加载了部分视图,然后加载javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!