brandonweiss / charge

⚡️ An opinionated, zero-config static site generator.
https://charge.js.org
MIT License
428 stars 19 forks source link

How to run JavaScript in browser? #1088

Open MarkLyck opened 3 years ago

MarkLyck commented 3 years ago

I'm setting up a dead simple page using Charge (love it btw.)

It's just a page telling the user they are blocked. But I need to display the URL that they are trying to access.

Normally I'd just use window.location for this. But when it's rendered server side there is no window.

And since no React is ever run in the browser, it never runs my line of JavaScript.

I tried creating another js file and importing it hoping it would get served with the HTML. But no :(

How do I serve a simple piece of JavaScript in the browser with Charge?

I'm even okay if it means adding a script tag to the React code, but that doesn't seem to work either :(