Swaagie / minimize

Minimize HTML
MIT License
162 stars 18 forks source link

Minimize synchronously #61

Closed tamtakoe closed 8 years ago

tamtakoe commented 9 years ago

Minimize synchronously as minimize.parseSync

Swaagie commented 9 years ago

what are your requirements for doing it sync?

tamtakoe commented 9 years ago

For example, If I caches templates

templates.forEach(function(template) {
    templatesCache.push(minimize.parseSync(template))
})

or other minor situations when it is uncomfortable to work with callbacks

Swaagie commented 9 years ago

Hmm i can see the usecase. However this is slightly out of minimizes' control. E.g. the DOMParser which is used by htmlparser2 is working with a callback https://github.com/fb55/domhandler#example. The only way this could work is if all 3 modules (minimize->htmlparser2->domhandler) would be working sync. Alternative solution to you caching.

require('async').map(templates, minimize.parse.bind(minimize), function (err, results) {
  templatesCache = results;
})

or similar

tamtakoe commented 9 years ago

I made issue https://github.com/fb55/domhandler/issues/21

https://github.com/kangax/html-minifier works synchronously, but has verbose API and has not gulp plugin.

fb55 commented 9 years ago

@Swaagie Calling the functions of the modules is a synchronous operation. Simply process the file, then access domhandler's dom property. The callback is also synchronous, you could have the handler assign the value to a local variable, then return it (not a nice solution, but works as well).

Swaagie commented 9 years ago

@fb55 thanks for replying :) As for the feature request, I hope I can spend a cycle on it this weekend.

Swaagie commented 9 years ago

Kinda fell of the radar, I'll try to spend a cycle on it asap

manuel-di-iorio commented 8 years ago

Looking for the sync feature :)

Swaagie commented 8 years ago

Finally fixed with https://github.com/Swaagie/minimize/pull/80 and released as 2.0.0