3 Replies - 2391 Views - Last Post: 05 August 2012 - 05:37 AM

#1 kiranp999   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-August 12

defer parsing of jquery

Posted 04 August 2012 - 11:22 PM

Hi All,
I am using below js code for jquery defer parsing.
Here is my code:
<script type="text/javascript">

function downloadJSAtonload() {
var element = document.createElement("script");
element.src = "jquery-1.3.2.js";
document.body.appendChild(element);

/*
$(document).ready(function(){
$("a").addClass("test");

});
*/


}

// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", downloadJSAtonload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtonload);
else window.onload = downloadJSAtonload;

</script>


How can call $(document).ready for the above code?
Please help me asap...

Thanks in advance ...

This post has been edited by Dormilich: 05 August 2012 - 03:44 AM
Reason for edit:: please use [code] [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: defer parsing of jquery

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: defer parsing of jquery

Posted 05 August 2012 - 03:45 AM

With the given code I see no reason to defer the loading of jQuery at all.
Was This Post Helpful? 0
  • +
  • -

#3 kiranp999   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-August 12

Re: defer parsing of jquery

Posted 05 August 2012 - 04:04 AM

View PostDormilich, on 05 August 2012 - 03:45 AM, said:

With the given code I see no reason to defer the loading of jQuery at all.


Thanks for the reply...

This is the sample code for jquery....
Actually i am using jqueries in my code. While checking the page speed, i need to defer parsing for some jqury files.

I am using below code for normal js external files for defer parsing.
Ex:
<script type="text/javascript">

function downloadJSAtonload() {
var element = document.createElement("script");
element.src = "temp.js"; //here using external js file
document.body.appendChild(element);

}

// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", downloadJSAtonload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtonload);
else window.onload = downloadJSAtonload;

</script> 


In this way how can i parse the jQuery files. so that i need to use $ or jquery variables in other script areas?
Please help me ...

OR
Is there any another way to defer parsing for jQueries?

Thanks...

This post has been edited by Dormilich: 05 August 2012 - 05:35 AM
Reason for edit:: please use [code] [/code] tage when posting code

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: defer parsing of jquery

Posted 05 August 2012 - 05:37 AM

before jQuery is loaded, there is no way to use any jQuery functionality. and considering page speed, external resources are cached by the browser.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1