gajus / usus

Webpage pre-rendering service. ⚡️
Other
805 stars 33 forks source link

Find a better way to inline CSS #1

Open gajus opened 7 years ago

gajus commented 7 years ago

See notes:

https://github.com/gajus/usus/blob/3edef93496971e329024aa1856babcd4cc15f453/src/usus.js#L27-L40

gajus commented 7 years ago

Related: https://github.com/gajus/usus/commit/c1d4f39f35b1534d97e21d64e9c61aedff36edcb

paulpflug commented 7 years ago

Nice tool your created. I would advise to do the inlining in the end in node with cheerio, which you already depend on..

  const rootOuterHTML = (await DOM.getOuterHTML({
    nodeId: rootDocument.root.nodeId
  })).outerHTML;

  await end();
  $ = cheerio.load(rootOuterHTML)
  $("head").append("<style>....")
  return $.html()

you will have the cost of one additional html parsing, but the code will be much cleaner..

or even easier a quick and dirty string replace..

  return rootOuterHTML.replace("</head>","<style>...</head>")