简体   繁体   English

如何限制BrowserSync的速度?

[英]How do I Throttle BrowserSync's speed?

How can I configure BrowserSync (from its API) to serve up content at a slower rate? 如何配置BrowserSync(从其API)以较慢的速度提供内容?

Ideally I'd like to be able to serve only certain files at the throttled rate, so when developing, localhost/index.html loads fast and localhost/dummyData.json loads slowly, so I can effectively demo loading states while developing web apps that decouple data and presentation. 理想情况下,我希望只能以限制的速度提供某些文件,因此在开发时, localhost/index.html快速加载,而localhost/dummyData.json缓慢加载,因此在开发Web应用程序时,我可以有效地演示加载状态分离数据和表示。

  1. start browser-sync: browser-sync start --server --files "src/*.*" 启动浏览器同步: browser-sync start --server --files "src/*.*"
  2. open the browser-sync UI (eg http://localhost:300 1 /) and go to "Network Throttle" 打开浏览器同步的用户界面(例如http:// localhost:300 1 /),然后转到“网络限制” 在此处输入图片说明
  3. select "Speed", then "Create Server" 选择“速度”,然后选择“创建服务器”
  4. Use the new server instance which is now running at the defined speed 使用现在以定义的速度运行的新服务器实例

HINT: 暗示:

You can run multiple throttled server instances an the same time - eg. 您可以同时运行多个受限制的服务器实例-例如。 to simulate CDN behavior (where the fastest wins) 模拟CDN行为(以最快的速度获胜)

You can also simulate latency! 您还可以模拟延迟! Have a look at the bs-latency Plugin ... 看看bs-latency插件 ...

From documentation 从文档

reloadThrottle reloadThrottle

Emit only the first event during sequential time windows of a specified duration. 在指定持续时间的连续时间窗口内仅发出第一个事件。

Example

browserSync.init({
        reloadThrottle: 300,
        server: {
            baseDir: 'dev/'
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过BrowserSync中间件设置会话cookie? - How do I set a session cookie via BrowserSync middleware? Webpack的HMR可以做哪些Browsersync无法做到的事情? - What Webpack's HMR can do which Browsersync is not able to do? 如何限制API请求的堆栈? - How can I throttle stack of api requests? 如何使用 NodeJS 和 browserSync 进行服务器端 HTML5 模式 URL 重写 - How to do serverside HTML5 mode URL Rewriting with NodeJS and browserSync 您如何对 Strapi API 进行速率限制/节流? - How do you rate limit / throttle a Strapi API? 如何限制Node.js / Express 4中的上传? - How can I throttle uploads in Node.js / Express 4? 在终端中停止Gulp时如何关闭BrowserSync的旧实例? - How do you close old instances of BrowserSync when stopping Gulp in Terminal? 您如何限制 Javascript for 循环与 API 调用,每秒 4 个调用块? - How do you throttle a Javascript for loop with an API call within, in chunks of 4 calls per second? 如何优化Firebase功能的响应速度 - how to optimize firebase function's response speed 如何在没有 Gulp 的情况下将 stream sass 导入浏览器同步? - How to stream sass into browserSync without Gulp?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM