PageSpeed : inline Small JavaScript
Published by Aslam
Inlining small JavaScript into the main HTML page cuts down on RTTs and delays in downloading other resources.
Browser will have to download your webpage first and then external files. making many request to server will cause rendering speed. inline any small javascript so your browser will not have to ask the server for each.
Why "inlining small JavaScript"?
inlining small JavaScript means that if you have external JavaScript like fisrt.js and second.js and the contents are little, then you can embed that codes inside the html code itself. thus the RTTs(Round Trip Times) and Delay in loading other resources cuts down.
How to inline Small JavaScript?
If you have small .js files, then you can inline the contents of that .js file by copying and pasting the contents inside script tags. will help you score on this rule.
For Example, you are calling small.js file like this:
<script src='small.js' type='text/javascript'<</script>
and contains below code :
var a=1;
var b=2;
var c= a+b;
Then you can copy that code and paste inside script tags.
<script type="text/javascript">
var a=1;
var b=2;
var c= a+b;
</script>
Pros and Cons
Inlining JavaScript files reduces RTTs (Round Trip Times)
Your JavaScript code will not be cached.
It is recommended to inline Small JavaScript files.
Comments
Post a Comment