有什么调试静态网页自动 watch 和刷新的 module 么? - CNode技术社区

有什么调试静态网页自动 watch 和刷新的 module 么?
发布于 13 年前 作者 jiyinyiyong 5041 次浏览 最后一次编辑是 9 年前

https://github.com/seajs/seajs/issues/224 看到 seajs 上出了个, 虽然实现的原理也不难... 自己做一个好的挺没底的, 可是又不是 seajs 用户... 请问各位有用过的模块能推荐么?

4 回复

=w= 消灭零回复,自己用file watch实现个呗,锻炼一下,没准你就是这类模块的先驱了

说的也是. 不过这么弄的话要尽量去掉任何模块的依赖... ws 也砍掉 不知道还有没有好的办法, 要不然 Ajax 轮询也郁闷了... 我想先看看个 server-send events 这个行不行...

忘了结帖... 写好了 https://github.com/jiyinyiyong/doodle 基于 websocket, 低版本 IE 不支持, 在我的 Ubuntu 上运行还是良好的. 刚开始尝试的记录写在这里: http://jiyinyiyong.github.com/blog/posts/120821-doodle-刷新页面.html

用法

sudo npm install -g doodle

命令行运行开始之后, 在 8071 打开一个 websocket 端口, 8072 一个 HTTP 端口, 浏览器段加入下面的代码接受 websocket 的信号来进行刷新:

html
 head
 title doodle test
 //- script(src='http://localhost:8072/doodle.js')
 :coffeescript
 hostname = location.hostname
 ws = new WebSocket "ws://#{hostname}:8071"
 ws.onmessage = (message) ->
 if message.data is 'reload'
 do location.reload
 body waiting

或者直接 <script> 引入 8072 端口的 /doodle.js 脚本, 就是上面的代码. 具体的 .html 文件可以看这里: https://github.com/jiyinyiyong/doodle/tree/master/example

回到顶部

AltStyle によって変換されたページ (->オリジナル) /