stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.06k stars 394 forks source link

Remove only some script tags #298

Closed kontrollanten closed 5 years ago

kontrollanten commented 5 years ago

Thanks for a really great module! It's very easy to get started.

I'm having a scenario where I don't want React to be included on client side (like this https://twitter.com/NetflixUIE/status/923374215041912833) and found the option removeScriptTags. The problem is that I want to keep some script tags (for tracking, etc). I think that may be a common scenario.

A suggested solution would be that removeScriptTags can either receive a bool (like today) or an array containing strings with CSS selectors.

The following config

{
  removeScriptTags: [
    ':not(.keep-me)',
   '[async]'
  ]
}

Will run

    Array.from(document.querySelectorAll("script:not(.keep-me), script[async]")).forEach(ell => {
      ell.parentElement && ell.parentElement.removeChild(ell);
    });

I'd be happy to create a PR for this. Any thoughts?

stereobooster commented 5 years ago

Not sure I want to load it with all possible features. More feature more ways to fail. I created removeScriptTags for fun and most likely I will drop it in v2. But you still can fork it and use your fork, because module installable from git url

kontrollanten commented 5 years ago

Sure, I understand! I'll do a fork for it 👍

kontrollanten commented 5 years ago

If anyone is interested, you can use my fork at https://github.com/kontrollanten/react-snap/pull/1

  "reactSnap": {
    "removeScriptTags": [
      ".selector-to-remove"
    ],
  },
Porges commented 5 years ago

Not sure I want to load it with all possible features. More feature more ways to fail. I created removeScriptTags for fun and most likely I will drop it in v2. But you still can fork it and use your fork, because module installable from git url

Please don't drop it, it's nice to be able to put react-snap in packages.json and get static pages out without having to edit anything else 🙂