Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can express and jade does not compress html?

I using express and jade, but when I debug I doesn't want jade compress my html, are there any way to pass an option jade globally and make it does not compress html.

like image 957
guilin 桂林 Avatar asked Nov 03 '11 08:11

guilin 桂林


People also ask

How does Express works?

Express provides methods to specify what function is called for a particular HTTP verb ( GET , POST , SET , etc.) and URL pattern ("Route"), and methods to specify what template ("view") engine is used, where template files are located, and what template to use to render a response.

What is RES flush?

res. flush. This module adds a res. flush() method to force the partially-compressed response to be flushed to the client.

What does compression middleware do?

The compression middleware is useful for compressing regular responses and server-sent event output. We can set options like compression level, chunk size, etc.

Is Express js a framework or library?

js/JavaScript) Express is a popular unopinionated web framework, written in JavaScript and hosted within the Node. js runtime environment.


3 Answers

If you use Express 3.x, you can control compression via app.locals.pretty. I usually enable it while development:

app.configure('development', function () {
    app.locals.pretty = true;
});
like image 93
Rob Zombie Avatar answered Oct 23 '22 08:10

Rob Zombie


In the time since this answer was written an option has been added to control this behaviour.

app.locals.pretty = true;

At the moment, no. This feature has been discussed here:

https://github.com/visionmedia/jade/pull/205

The html doesn't actually get compressed or minified by default, though. It's just not formatted nicely. The simplest way I've found to make it human-readable is to use Chrome's dev tools, which give you a nice foldable representation of the source.

like image 34
davidbanham Avatar answered Oct 23 '22 07:10

davidbanham


You can use Jade Comments to annotate your code for viewing in the browser.

//h1
h1 Some Title
//p
p some content

will output

<!--h1-->
<h1>Some Title</h1>
<!--p-->
<p>some content</p>

The template is already compiled once it leaves the server, so if you wanted to view the template in the browser you would have to write a plugin that de-compiles html to jade and than display the decompiled version.

like image 45
Chris Biscardi Avatar answered Oct 23 '22 06:10

Chris Biscardi