By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

size of Javascript file

100+
P: 184
Hi All,
Is there a max limit on the size of a Javascript file that can be used in web environment?

How can we set header/expires for a Javascript file alone (and not for the entire JSP,HTML, etc).

please correct me if i'm wrong.. do needfull.
Thanks.
Jan 23 '09 #1
Share this Question
Share on Google+
13 Replies


acoder
Expert Mod 15k+
P: 16,027
What size are we talking about here? What problem does it cause?

You can set headers if you use JSP to generate the JavaScript file and include like this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="includes/js.jsp"></script>
Jan 23 '09 #2

100+
P: 184
@acoder

Hi Acoder,
1. since my application has 80 -90 javascript files to load,it causes performance issue.hence i started combining the javascript files.And thus, is there any limit for maximum size of javascript in web environment?
2. yes Acoder ,ofcourse,what u said is rite for header/expires.But my query is very close to javascript. for jsp we can set header/expires.. But for me header/expires need to be set only static content (javascript).

Hope u got my query?
Jan 23 '09 #3

gits
Expert Mod 5K+
P: 5,390
to reduce the filesize of JavaScript(s) you may use a 'minifyier', which just drops useless whitespaces etc. ... in you productive version of the script-file(s). have a look here to get the basic idea of it.

kind regards
Jan 23 '09 #4

acoder
Expert Mod 15k+
P: 16,027
That is a lot of files. Are you sure you need that many? The limit depends on the browser and the system. Also, note that once you include a file using script tags, it can be cached, so page load the second time round should be faster.
Jan 23 '09 #5

100+
P: 184
@acoder
Acoder,
yeah!... Acoder.. ofcourse, time taken to load the second round should be less , because of caching. Eventhough it cached the request for the javascript files in web server is received.. and hence again causing the time delay (performance issue) to load the page.
Jan 23 '09 #6

100+
P: 184
@gits
Gits,
Thanks for your inputs.. is there any other way to reduce the file size other than using tools like JSmin etc... And more is , from your refrence link
i found the below comment
"you should use a build script to reduce the size of JavaScript and CSS before every deployment stripping comments and whitespace"..

what does build script means?
Jan 23 '09 #7

gits
Expert Mod 5K+
P: 5,390
@gaya3
of course ... you could do it manually ... ;) ... and/or use the gzip-compression (when your webserver is able to do so) ... have a look here

@gaya3
this is a script that just starts to minify the files when you want to deploy it to the productive machine ... so you don't need to minify your dev-version so that you could easyly work with them ... and while this is not required in the production version every comment etc. could be dropped before releasing the files to production

kind regards
Jan 23 '09 #8

100+
P: 184
Gits,
Thanks for your inputs... From the link you suggested, i found the below comment...
"For static components: implement "Never expire" policy by setting far future Expires header "
How do i set the expires for static components... pl provide me some samples for javascript....
Jan 24 '09 #9

100+
P: 184
@gits
Gits,
As mentioned in the refrenced link... where do i suppose to add the
below comments in my application.. in header?
" Accept-Encoding: gzip, deflate
Content-Encoding: gzip"
if so please provide me some samples....
Does Gzipping reduces the response size by about 70% ? really?
will the time taken to download the javascript file get reduce?
Jan 24 '09 #10

gits
Expert Mod 5K+
P: 5,390
i think both of it has to be done through the Apache configuration ... may be this link does help you?

kind regards
Jan 25 '09 #11

100+
P: 184
Ho ! ok Gits.. could you please say me how to add "Never expires" for the static components (javascript files) in headers.
Jan 27 '09 #12

gits
Expert Mod 5K+
P: 5,390
hi ... i'm not an Apache expert ... and as i said i think it is a webserver configuration issue ... may be you should ask in the corresponding forum which depends on the webserver you use ...

kind regards
Jan 27 '09 #13

Dormilich
Expert Mod 5K+
P: 8,639
@gaya3
if you have Apache and the mod_headers module installed, have a look at the above mentioned link. otherwise you may try the ExpiresByType directive
Jan 27 '09 #14

Post your reply

Sign in to post your reply or Sign up for a free account.