zalando / tailor

A streaming layout service for front-end microservices
http://www.mosaic9.org
MIT License
1.73k stars 141 forks source link

async doesn't work when I use with gzip compression in express #264

Open WarisR opened 6 years ago

WarisR commented 6 years ago

In index.js(Node.js), I use express and I add compression middleware to do a gzip compression

const app = express();
app.use(compression());
app.get(['/', '/index'], (req, res) => {
  req.url = req.originalUrl === '/' ? '/index' : req.originalUrl;
  tailor.requestHandler(req, res);
});

index.html

<fragment src="http://localhost:3000" async></fragment>

I added async in index.html but it doesn't work properly and still load synchronously.

Does Async in Tailor support gzip compression? Anyone has a workaround?

vigneshshanmugam commented 5 years ago

All the fragments supports gzip compression, There is no differentiation between sync and async fragments except async fragments are streamed later on the page.

trickpeeraze commented 5 years ago

I think he mean by the Tailor itself that doesn't support compression, not fragments.

WarisR commented 5 years ago

@vigneshshanmugam Yes, I meant the Tailor doesn't work property with async+compression. It would wait all fragments loaded before render in the browser even if we use async.

WarisR commented 5 years ago

@vigneshshanmugam Do you compress your website (Tailor level not a fragment level) by nginx/express/etc.? I use this library for compression. https://github.com/expressjs/compression and also try Nginx. It doesn't work with async.

vigneshshanmugam commented 5 years ago

We do compress it using our in house proxy server Skipper. I am not sure why it doesn't work with compression. I will try to check and update you.

WarisR commented 5 years ago

@vigneshshanmugam Thank you. Do you suggest me to use Skipper? Is only Tailor is enough for production?

vigneshshanmugam commented 5 years ago

@WarisR Sorry somehow lost your message. Tailor is indeed enough for handling the load for production. But since GZIP is a CPU heavy task, I would say its better to do it at the proxy level like using Skipper/Nginx etc .