|
!!!Where To Put Javascript
|
!!!!Location:
|
-Javascript is best placed in one of two locations. Either in a .js file or in a package's header_inc.tpl file. ALL package .js files should go in a __scripts/__ directory in their package. It is not always advantageous however to put javascript in .js files. Use of js files causes the browser to make more http requests. If there are a lot of js files required then this can slow page load time. For small amounts of javascript its better to put it into the header_inc.tpl file where it will be rendered inline in the <HEAD> tag. It is ok to also put the js in a separate template and include that in the header_inc.tpl file.
|
+Javascript is best placed in one of two locations. Either in a .js file or in a package's header_inc.tpl file. ALL package .js files should go in a __scripts/__ directory in their package. It is not always advantageous however to put javascript in .js files. Use of js files causes the browser to make more http requests. If there are a lot of js files required then this can slow page load time. For small amounts of javascript its better to put it into the header_inc.tpl file where it will be rendered inline in the HEAD tag. It is ok to also put the js in a separate template and include that in the header_inc.tpl file. |
|
Some bitweaver wide .js files will live in util/ but that will be rare, most .js files should be in their package.
|
|
-AVOID INLINE JS AS MUCH AS POSSIBLE INSIDE THE BODY TAGS. Sometimes this is hard to do, but in most cases you can. It is poor practice to litter HTML with <SCRIPT> tags. Sometime people do this to cause something to be rendered on load. If you want a function called onload you should instead you should assign the function to the body onload event. You can do this in your php by assigning your javascript function like this:
|
+AVOID INLINE JS AS MUCH AS POSSIBLE INSIDE THE BODY TAGS. Sometimes this is hard to do, but in most cases you can. It is poor practice to litter HTML with SCRIPT tags. Sometime people do this to cause something to be rendered on load. If you want a function called onload you should instead you should assign the function to the body onload event. You can do this in your php by assigning your javascript function like this: |
|
{code}$gBitSystem->mOnload[] = 'BitPackage.someFunction();';{/code}
|
|