12 Replies Latest reply: Nov 3, 2014 11:38 AM by jonas-vacek RSS

    Removing comments from all the code?

    billhdz Community Member
      Hello Folks!

      What is the best strategy to remove ALL the comments from the .html and .css files before publishing them?
      The goal is to end up with a full local website ( with comments and all ), and a cleaned up version ( with all comments removed ) for publishing. What work flow do you use to accomplish this? Is there a way to have dreamweaver do this automatically?

      Thanks!
      William
        • 1. Re: Removing comments from all the code?
          Newsgroup_User Community Member
          > a cleaned up version ( with all comments removed ) for publishing

          Why bother? You create lots of extra work for yourself with this.

          --
          Murray --- ICQ 71997575
          Adobe Community Expert
          (If you *MUST* email me, don't LAUGH when you do so!)
          ==================
          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
          ==================


          "billhdz" <webforumsuser@macromedia.com> wrote in message
          news:gmfahk$6gm$1@forums.macromedia.com...
          > Hello Folks!
          >
          > What is the best strategy to remove ALL the comments from the .html and
          > .css
          > files before publishing them?
          > The goal is to end up with a full local website ( with comments and all ),
          > and
          > a cleaned up version ( with all comments removed ) for publishing. What
          > work
          > flow do you use to accomplish this? Is there a way to have dreamweaver do
          > this
          > automatically?
          >
          > Thanks!
          > William
          >
          >

          • 2. Re: Removing comments from all the code?
            Newsgroup_User Community Member
            .oO(billhdz)

            > What is the best strategy to remove ALL the comments from the .html and .css
            >files before publishing them?

            Why? To save 1 or 2 KB? If you're worried about the filesize, have a
            look at HTTP compression instead, that would yield much better results.
            Or is there another reason?

            Micha
            • 3. Re: Removing comments from all the code?
              billhdz Community Member
              This is a practice that I like to get into. Clean code online.
              I know is not necessary, but I like to do it. Is a personal preference.
              Thanks for the reply.

              There has to be a way to automate this. Any ideas?
              • 4. Re: Removing comments from all the code?
                Newsgroup_User Community Member
                >>> There has to be a way to automate this. Any ideas?

                Sitewide Find & Replace with Regular Expressions might do what you want but
                I'm not familiar enough with RegEx to assist you I'm afraid.

                However, I think it's far more trouble than it's worth and I'm not aware of
                any web designers who clean out their comments before putting their websites
                online.

                I also find comments in the online code to be a valuable learning tool when
                I'm examining the source code for a website. I get valuable insights into
                the thought process of the web designer and how they structured their code.

                --
                Regards

                John Waller

                • 5. Re: Removing comments from all the code?
                  Newsgroup_User Community Member
                  But- if any of the comments are for dreamweaver specific things, like
                  templates or similar, would have to do something like copy the files to
                  another folder, then strip the comments. so that they are preserved in the
                  original site.

                  Try this-
                  Create another site definition with a new empty local site folder
                  Go to original site.
                  dw menu->modify->templates->Export without markup
                  Set the destination folder as the new site's local folder

                  does that clean the files?

                  --
                  Alan
                  Adobe Community Expert, dreamweaver

                  http://www.adobe.com/communities/experts/



                  • 6. Re: Removing comments from all the code?
                    Newsgroup_User Community Member
                    It's not that it's not necessary. It's that it's a useless affectation.
                    Spend the time making your code validate instead. Really.

                    --
                    Murray --- ICQ 71997575
                    Adobe Community Expert
                    (If you *MUST* email me, don't LAUGH when you do so!)
                    ==================
                    http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                    http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                    ==================


                    "billhdz" <webforumsuser@macromedia.com> wrote in message
                    news:gml5s0$elh$1@forums.macromedia.com...
                    > This is a practice that I like to get into. Clean code online.
                    > I know is not necessary, but I like to do it. Is a personal preference.
                    > Thanks for the reply.
                    >
                    > There has to be a way to automate this. Any ideas?
                    >

                    • 7. Re: Removing comments from all the code?
                      Thurstanh

                      Options - Not fully automated, but it's a bit closer then some of the answers above. I know this post is old, but I came upon it looking for the same answer and was so frustrated with the many crap answers that I thought I would post something useful for future searchers.

                       

                      1. Use this dreamweaver query

                      <?xml version="1.0"?>

                      <dwquery>

                        <queryparams matchcase="false" ignorewhitespace="false" useregexp="true" wholeword="false" />

                        <find>

                          <qtext qname="/\*[\S\s]+?(?=\*/)\*/" qraw="true"></qtext>

                        </find>

                        <replace action="replaceText" param1="" param2=""/>

                      </dwquery>

                       

                      more details on use at http://foundationphp.com/tools/css_comments.php

                       

                      2. Use an online minify tool such as http://www.shrinker.ch/

                       

                      For those who answered with: why bother?  If you don't have an answer then don't post an 'answer'. Your comments are of little value and just hinder others looking for the same answer.

                       

                      I started with a dreamweaver template and wanted to get rid of the comments because I didn't need them and they were simply taking up space and were annoying to sift through to find the parts I wanted to edit.

                       

                      I ended up minifying then applying source formatting in dreamweaver to get it cleaned up.

                       

                      By the way the 'few' kb/s that were saved in this case turned out to be an 80% reduction.  Sure it was only 5kb reduction from 6 to 1kb, however if you had 100,000 people visit your site in a month that is half a gig of data extra and that is just one file.

                      • 8. Re: Removing comments from all the code?
                        Nancy O. CommunityMVP

                        I use code comments to help me and others understand what "thinking" went into the project during development.  Comments are beneficial to me & essential for others who may eventually take over the site. I never strip them out.  YMMV.

                         

                         

                        Nancy O.

                        • 9. Re: Removing comments from all the code?
                          Reverend2009 Community Member

                          I agree.  Most of these responses are infuriating, and typical of some know-it-all dev's.  I know not every dev is like this but it's very common, and sadly, especially so on forums.

                           

                          So...

                           

                          "Why remove comments?"  ... I have inherited a website project that includes a CSS file with a total of well over 9000 lines.  It is so huge and messy that it's actually slowing DW right down.  I have trimmed about 2,500 of them, and I believe I can trim another 20 - 30% just by removal of the commented out sections, but that's a time-consuming job on an 8000 line file.

                           

                          So, Thurstanh, thanks very much for the USEFUL reply.

                          • 10. Re: Removing comments from all the code?
                            DaffodilAzalea

                            Thanks, Thurston, for the one useful reply. I too inherited some very messy code, created by someone who used Word to build websites. I came here to find out how to quickly remove it.

                             

                            I'm not interested in explaining why I want comments removed, nor am I interested in lessons as to why comments are good to have. I want an answer to my problem so I can get on with my work. I came here to find out of Dreamweaver could help me. And yes, Nancy, my mileage varies very much from yours.

                             

                            I did find an answer on another site: Under 'Commands' in top menu bar, choose 'Clean up HTML / XHTML'. In dialog box, chose 'Non-Dreamweaver HTML comments'.  Silly me -- I use this function all the time to clean up code and get rid of unwanted tags but never noticed it could get rid of comments as well. 

                            • 11. Re: Removing comments from all the code?
                              Jon Fritz II CommunityMVP

                              You can also use Regular Expressions in DW's Find/Replace tool to take comments out:

                               

                              http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions_pt1.html

                               

                              Specifically Part 2 talks about removing CSS comments...

                               

                              http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions_pt2.html

                              • 12. Re: Removing comments from all the code?
                                jonas-vacek

                                To those looking for an actual answer to the question, regardless of your personal opinion, here goes:

                                 

                                Bring up your Find & Replace (CMD+F or CTRL+F I assume), paste the string below into the "Find" field. You can put simply nothing into the "Replace" field and press the "Replace all" button to then get rid of all comments. It's the .* that does the trick with looking for anything inside the two bits.

                                <!--.*-->

                                As others did say, however, comments are great and you should generally stick to using them and leaving them in your code.

                                 

                                But If you get something generated by a wysiwyg, you might as well remove all the commented nonsense that doesn't do anything anyway and has absolutely no value (in contrast to a comment written by an intelligent human being, of course).

                                 

                                Hope you managed to finish whatever it was 5 years ago...