code_junkie

What are the ways to minimize page wait from external javascript callouts?

Nov 11th, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. $(function(){
  2. // Document is ready
  3. });
  4.  
  5. jQuery(function($) {
  6. // Your code using failsafe $ alias here...
  7. });
  8.  
  9. jQuery(function($) {
  10. $.getScript("http://www.yourdomain.com/scripts/somescript1.js");
  11. $.getScript("http://www.yourdomain.com/scripts/somescript2.js");
  12. });
  13.  
  14. <html>
  15. <head>
  16. <title>Test Page</title>
  17. <script type="text/javascript">
  18. window.onload = function () {
  19. alert(document.getElementsByTagName("body")[0].className);
  20. };
  21. </script>
  22. <style type="text/css">
  23. .testClass { color: green; background-color: red; }
  24. </style>
  25. </head>
  26. <body class="testClass">
  27. <p>Test Content</p>
  28. </body>
  29. </html>
  30.  
  31. <html>
  32. <head>
  33. <title>Test Page</title>
  34. <script type="text/javascript">
  35. alert("Are you seeing a blank page underneath this alert?");
  36. </script>
  37. <style type="text/css">
  38. .testClass { color: green; background-color: red; }
  39. </style>
  40. </head>
  41. <body class="testClass">
  42. <p>Test Content</p>
  43. </body>
  44. </html>
  45.  
  46. if (!window.addOnLoad)
  47. {
  48. window.addOnLoad = function (f) {
  49. var o = window.onload;
  50.  
  51. window.onload = function () {
  52. if (typeof o == "function") o();
  53. f();
  54. }
  55. };
  56. }
  57.  
  58. window.addOnLoad(function () {
  59. alert(document.getElementsByTagName("body")[0].className);
  60. });
  61.  
  62. dojo.addOnLoad(function () {
  63. alert(document.getElementsByTagName("body")[0].className);
  64. });
  65.  
  66. $(function () {
  67. alert(document.getElementsByTagName("body")[0].className);
  68. });
  69.  
  70. if (!window.addScript)
  71. {
  72. window.addScript = function (src, callback) {
  73. var head = document.getElementsByTagName("head")[0];
  74. var script = document.createElement("script");
  75. script.src = src;
  76. script.type = "text/javascript";
  77. head.appendChild(script);
  78. if (typeof callback == "function") callback();
  79. };
  80. }
  81.  
  82. window.addOnLoad(function () {
  83. window.addScript("example.js");
  84. });
  85.  
  86. dojo.addOnLoad(function () {
  87. dojo.require("dojo.io.script");
  88. dojo.io.script.attach("exampleJsId", "example.js");
  89. });
  90.  
  91. $(function () {
  92. $.getScript("example.js");
  93. });
Add Comment
Please, Sign In to add comment