I'm going to implement Defer loading of JavaScript approach because as per current structure JavaScript is being called in
<head> element which is taking long response time. So I just want to add this JavaScript after complete DOM load. Here is code in cshtml file
Here is what I'm planning to do: I will remove the @Scripts.Render("~/bundles/javascript") from
<head> section. Then copy the src value from rendered view source and use given below
<scripttype="text/javascript">// Add a script element as a child of the bodyfunction downloadJSAtOnload(){var element = document.createElement("script");
element.src ="/bundles/javascript?v=abcdefghikeriotterpoggkjs-fskdf";
document.body.appendChild(element);}// Check for browser support of event handling capabilityif(window.addEventListener)
window.addEventListener("load", downloadJSAtOnload,false);elseif(window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);else
window.onload = downloadJSAtOnload;</script>
Am I doing correct? My doubt is Does this value
v=abcdefghikeriotterpoggkjs-fskdf
throughout the application remain same or it can be changed. If it remain same then I think there won't be any issue. Please suggest.
None
0 Points
10 Posts
Defer loading of Javascript approach in asp.net mvc
Nov 27, 2016 06:22 AM|sukhi.ece@gmail.com|LINK
I'm going to implement Defer loading of JavaScript approach because as per current structure JavaScript is being called in
<head>
element which is taking long response time. So I just want to add this JavaScript after complete DOM load. Here is code in cshtml fileLayout.cshtml
Rendered html view source:
Here is what I'm planning to do: I will remove the
@Scripts.Render("~/bundles/javascript")
from<head>
section. Then copy thesrc
value from rendered view source and use given belowAm I doing correct? My doubt is Does this value
throughout the application remain same or it can be changed. If it remain same then I think there won't be any issue. Please suggest.
</div>All-Star
18815 Points
3831 Posts
Re: Defer loading of Javascript approach in asp.net mvc
Nov 28, 2016 06:28 AM|Nan Yu|LINK
Hi ,
Seems you are following this article :
https://varvy.com/pagespeed/defer-loading-javascript.html
Just try append the specified js files with multi script elements and check whether it works .
Best Regards,
Nan Yu
None
0 Points
10 Posts
Re: Defer loading of Javascript approach in asp.net mvc
Nov 28, 2016 12:37 PM|sukhi.ece@gmail.com|LINK
Yes correct...so here I have 2 questions:
1) Does above implementation which I did in post is correct
2) Does this value
remain same through the applications?
because in cshtml file it's rendered through
but I copy that value from view source and appended in script code.
Member
492 Points
194 Posts
Re: Defer loading of Javascript approach in asp.net mvc
Dec 02, 2016 08:24 AM|meeyourmark|LINK
Hi ,
Then try it to check whether it works .
As @Nan Yu said , "append the specified js files with multi script elements" , not mixed use bundles
:)