bensheldon / spectator_sport

Record and replay browser sessions in a self-hosted Rails Engine.
https://spectator-sport-demo-1ca285490d99.herokuapp.com/
MIT License
156 stars 3 forks source link

Thoughts on frontend assets, no-build, and browser compatibility #16

Open bensheldon opened 1 month ago

bensheldon commented 1 month ago

I think of Spectator Sport as having two separate frontend systems:

The Recorder

I expect this to appear in the parent application as a single JavaScript script served via a <script> tag

By default, the script file will be served via the application (route/controller/action/render(file:)) rather than the asset pipeline. I think the Rails asset pipeline is too fragmented in implementation right now to provide a simple set of instructions that would be compatible with 95% of Rails applications. That said, I expect the script to be static (e.g. not ERB) so that a developer could copy-paste and vendor it into their pipeline if they choose to (but I would consider that “advanced” set up).

I want all assets (JS / CSS) to not require any build-step, even for gem development. The reason for this is to make it simple to fork this gem, make a simple change, and still easily allow bundling via a Gemfile git: reference.

I believe it can be written in ES6. I think fetch support is a reasonable browser compatibility requirement, which means that ~ES2017 is reasonable to target, which does have JS classes and arrow functions. Service Workers are about on the edge. 95% browser share is probably sufficient, though if we get bug reports and there is a simple and more compatible replacement, I think we should do it for greater compatibility.

The Dashboard

I wrote up a little more over here about the Dashboard: https://github.com/bensheldon/spectator_sport/issues/3#issuecomment-2381026367

More simply, it can be done pretty simple with import maps (the browser feature, not the Rails gem) and no build.