Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:02:25+00:00 2026-06-18T12:02:25+00:00

I’ve got a Backbone application, organized into modules using Require.js. One of these modules

  • 0

I’ve got a Backbone application, organized into modules using Require.js. One of these modules contains a Handlebars helper, which has a method I use to pull a legal header off of all our HTML templates for each View. The header is contained in an HTML comment, so I use the following regex to strip it off:

/<!--[\s\S]*?-->/g

Now, when I optimize (concatenate/compile/minify) the application using r.js, I’m doing the same removal of HTML comments using the onBuildWrite() method of r.js:

onBuildWrite: function (moduleName, path, contents) {
    var htmlCommentRegex = /<!--[\s\S]*?-->/g;

    return contents.replace(htmlCommentRegex, "");
},

Now, unfortunately, this means that when the Require.js module containing the Handlebars helper is pulled into the r.js optimized build, the regex literal within the helper is stripped out, causing my entire r.js build to bomb out.

I’ve tried to resolve the issue by selectively applying the regex in onBuildWrite() to all modules EXCEPT the helper:

onBuildWrite: function (moduleName, path, contents) {
    var htmlCommentRegex = /<!--[\s\S]*?-->/g;

    if (moduleName !== "helpers/handlebars.compileClean") {
        contents = contents.replace(htmlCommentRegex, "");
    }

    return contents;
},

But this doesn’t appear to work when uglification is enabled in the r.js configuration; the regex STILL seems to be running on the entire built script, including the helper, causing the build to bomb out.

If uglify is disabled in the r.js config, everything works fine.

Anyone have any ideas why uglify would break this? Would switching to a different regex, that would capture HTML comments but IGNORE the HTML comment regex literal, solve the issue? If so, what would that regex look like?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:02:49+00:00Added an answer on June 18, 2026 at 12:02 pm

    Change your regexp to:

    var htmlCommentRegex = /[<]!--[\s\S]*?-->/g;
    

    The single-character [<] class is equivalent to < as far as the RE processor is concerned, but now the RE no longer matches itself.

    Another way is to escape one of the literal characters in the RE:

    var htmlCommentRegex = /<\!--[\s\S]*?-->/g;
    

    Or you could build the RE from strings:

    var htmlCommentRegex = new RegExp('<!'+'--[\s\S]*?-->', 'g');
    

    If r.js is optimizing all these back to the original text, try this:

    var commentPrefix = '<!';
    var htmlCommentRegex = new Regexp(commentPrefix+'--[\s\S]*?-->', 'g');
    

    Hopefully it doesn’t do enough code analysis to undo this obfuscation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.