size of Javascript file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gaya3
    New Member
    • Aug 2007
    • 184

    size of Javascript file

    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.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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:
    Code:
    <script type="text/javascript" src="includes/js.jsp"></script>

    Comment

    • gaya3
      New Member
      • Aug 2007
      • 184

      #3
      Originally posted by acoder
      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:
      Code:
      <script type="text/javascript" src="includes/js.jsp"></script>

      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?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        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

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          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.

          Comment

          • gaya3
            New Member
            • Aug 2007
            • 184

            #6
            Originally posted by acoder
            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.
            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.

            Comment

            • gaya3
              New Member
              • Aug 2007
              • 184

              #7
              Originally posted by gits
              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
              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?

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                Originally posted by gaya3
                ... is there any other way to reduce the file size other than using tools like JSmin etc...
                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

                Originally posted by gaya3
                what does build script means?
                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

                Comment

                • gaya3
                  New Member
                  • Aug 2007
                  • 184

                  #9
                  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....

                  Comment

                  • gaya3
                    New Member
                    • Aug 2007
                    • 184

                    #10
                    Originally posted by gits
                    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
                    kind regards
                    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?

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5390

                      #11
                      i think both of it has to be done through the Apache configuration ... may be this link does help you?

                      kind regards

                      Comment

                      • gaya3
                        New Member
                        • Aug 2007
                        • 184

                        #12
                        Ho ! ok Gits.. could you please say me how to add "Never expires" for the static components (javascript files) in headers.

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          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

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            Originally posted by gaya3
                            could you please say me how to add "Never expires" for the static components (javascript files) in headers.
                            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

                            Comment

                            Working...