# Re: mod\_strip newline substitution problem

**URL:** <https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532>\
**Category:** NGINX\
**Created:** [May 3, 2008, 5:29am UTC](https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532 "2008-05-03T05:29:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [May 3, 2008, 5:29am UTC](https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532/1 "2008-05-03T05:29:19Z")

</div>

Hi Evan

> The problem is that I can’t replace newlines before end tags with a space:

Is that going to make it even more challenging to add support for  
removing unnecessary spaces from JavaScript files? Would love to see  
support for that one day. Currently we are doing this with a filter at  
the web server level and I bet doing it at the nginx level would be much  
more efficient.

```
  ____________________________________________________________________________________

```

Be a better friend, newshound, and  
know-it-all with Yahoo! Mobile. Try it now.  
[http://mobile.yahoo.com/;\_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ](http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ)

---

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [May 3, 2008, 6:07am UTC](https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532/2 "2008-05-03T06:07:53Z")

</div>

could also control it from a “build” level

do some minifying or javascript compression, file combining and anything  
else

---

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [May 3, 2008, 8:49pm UTC](https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532/3 "2008-05-03T20:49:42Z")

</div>

Rt Ibmer \<rtibmx@…\> writes:

> Hi Evan
> 
> > The problem is that I can’t replace newlines before end tags with a space:
> 
> Is that going to make it even more challenging to add support for removing  
> unnecessary spaces from JavaScript files? Would love to see support for  
> that  
> one day. Currently we are doing this with a filter at the web server  
> level and  
> I bet doing it at the nginx level would be much more efficient.

Yes. The module will need to be rewritten to parse other languages. I’d  
like to  
use Ragel, a state-machine generator that operates on data buffers.

[http://www.cs.queensu.ca/~thurston/ragel/](http://www.cs.queensu.ca/~thurston/ragel/)

Evan

---

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [May 3, 2008, 9:38pm UTC](https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532/4 "2008-05-03T21:38:30Z")

</div>

Hi all,

We (soitu.es) has a module which cleans HTML and inserts blocks of HTML.

This is our first released module (called  
ngx\_http\_html\_clean\_filter\_module.c) and you could read the description  
(in spanish) at:

```
 http://www.soitu.es/soitu/2008/04/28/met/1209378259_661127.html

```

An usage example is:

location / {  
html\_clean\_active on;

```
 # Pixel counter and common JS to all pages.
 html_clean_pxlcntrblock '<div style="display:none">\

```

![](https://www.ruby-forum.com/pxlctl.gif)\

';

```
 # Only common JS, no pixel counter
 html_clean_xcldpxlcntrblock '<div style="display:none">\

```

';

}

A few lines about

- Removes all white spaces at the begining of lines and empty lines.

- Removes all HTML comments with a pattern like:

- Blocks surrounded by #IB and #EB are served without modifications:

- The text defined in “html\_clean\_pxlcntrblock” is inserted after

 tag (we used to count pixels and common JS includes). The problem is that we have pages which could not be counted (examples: iframes or frames), so you'll need a before and the text defined in "html\_clean\_xcldpxlcntrblock" will be inserted.

We are using in our production NGINX servers.

Cheers,

---

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [May 4, 2008, 12:24am UTC](https://www.ruby-forum.com/t/re-mod-strip-newline-substitution-problem/136532/5 "2008-05-04T00:24:50Z")

</div>

Hi Raul,  
Your module works fine 🙂 (also against nginx nginx-0.6.30).  
I’m using it on my production server with mod\_stripe to cleanup fastcgi  
output code 🙂

Thanks,  
Tomek
