New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Solved] Minify HTML with EJS #2188
Comments
This forum is for reporting bugs in the Sails core; support questions should go in the Google Group or StackOverflow (where you've already posted this). |
Alright 👍 |
@sgress454 the StackOverflow thread is closed, and I still have no answer. 👎 |
@sgress454 Would be really nice to know how to do this. As https://groups.google.com/forum/#!topic/sailsjs/zSxv7uJEVrM There is no answer right now. Thank you. |
+1 |
@marceloboeira unfortunately I couldn't get that SO question re-opened, where I had basically answered you in the comments. The problem is that when you declare a default layout with EJS, Sails overrides your view configuration in order to use
should do the trick. |
@sgress454 thanks! It worked! Only this line is different: options.locals._layoutFile = '/layout.ejs'; |
@marceloboeira Works both ways for me. In any case why don't you go ahead and post this as an answer on the new StackOverflow question! |
@sgress454 alright! |
👍 It worked... This would be super useful if enabled by default in production... |
Keep an eye out for the time it takes when everytime the page is requested and the time you receive the file For me normal file was sent in 179ms and when minify was enabled it took up to 900ms So there is a problem here. |
@sahanDissanayake How do you test the time? Newbie here... |
@mewben If you are using Google Chrome use https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en And then you can just enter the link and then you will see the results. Let me know |
Seems ok to me... I'm using a fresh sails install in my local dev... |
I mean no noticeable difference at all... without minification, I got 75ms... With minification, i got 65ms. on homepage... |
how can we use it for multiple layouts ? |
@iswanj tricky question, ... |
@mewben I should test several times the same page, I didn't have the time to test it yet. |
@marceloboeira I already solved that var minify = require('html-minifier').minify;
var ejs = require('ejs-locals');
var parsing = function(path, options, fn) {
options.locals = options.locals || {};
// use default 'layout.ejs' if res.locals.layout is not set
options.locals._layoutFile = '../' + options.layout;
ejs(path, options, function(err, str) {
str = minify(str, {collapseWhitespace: true, removeComments: true});
return fn(err, str);
});
};
module.exports.views = {
engine: {
ext: 'ejs',
fn: parsing
},
layout: false
}; |
👍 |
Why this doest work?
The text was updated successfully, but these errors were encountered: