On an average I have 30-50 lines of javascript specific to the page (it is not common). How should I structure my Javascript code so that it gets downloaded in an optimal manner on the client.
If I put that in a common Javascript file then the initial page download will take time because it will even download Javascript code that is not for that page.
If I put it embedded within the page itself then disadvantage is that it is never cached.
How should I structure it in optimal manner? I have round about 30-50 pages in my application.
When developing, use a logic folder structure so you can put all files in a folder and you can find them easier. When in production, concat and minify your code/files and use one reference to that minified file.
If you want to seperate even in production, think of a way to concat files as much as possible and minify that files. To load files when needed, you can think of a library as RequireJS.