Is there a way to “hot swap” JavaScript code within the browser?

后端 未结 6 1418
南方客
南方客 2020-12-28 09:16

Is there any tool that enables you to \"hot swap\" JavaScript contents while executing a webpage?

I am looking for something similar to what HotSpot does for Java,

6条回答
  •  不知归路
    2020-12-28 09:44

    You can easily hot-reload JavaScript code with the RequireJS front-end module system, I wrote an article about it recently (September 2015)

    https://medium.com/@the1mills/hot-reloading-with-react-requirejs-7b2aa6cb06e1

    you basically delete the cache for an AMD module and RequireJS will go fetch the new one from the filesystem.

    the trick is to use websockets (socket.io works fine) to tell the browser that the file has changed, and to delete the cache and re-require the file.

    the rest of the info is in the article

提交回复
热议问题