简体   繁体   English

是否有一个JavaScript加载程序可以将套接字数限制为1或2

[英]Is there a javascript loader which can limit the number of sockets to 1 or 2

I want to create a networked embedded device with an HTML5/JS one-page AJAX configuration application. 我想用HTML5 / JS一页AJAX配置应用程序创建一个联网的嵌入式设备。

My problem is: browsers open too much connections nowadays, in my device the number of concurrent connections is maximum 4 with a TCP stack in hardware (please remember, it is an embedded device). 我的问题是:如今浏览器打开的连接过多,在我的设备中,使用硬件中的TCP堆栈的并发连接数最大为4(请记住,它是嵌入式设备)。

Any request through a socket > 4 seems to be lost, one has to press F5 until a combination of application and cache elements is sitting in the browser. 通过套接字> 4的任何请求似乎都丢失了,必须按F5直到浏览器中包含应用程序和缓存元素的组合。

Now my initial idea was to use a js loader (with the favicon as a data-url) as index document, which in turn loads the rest of the application one by one (perhaps also with progress bar, but that would be luxury). 现在,我最初的想法是使用js加载程序(将favicon作为数据URL)作为索引文档,这反过来依次加载应用程序的其余部分(也许还带有进度条,但这很奢侈)。

In theory this should assure that there is only one connection opened at one time. 从理论上讲,这应确保一次仅打开一个连接。

All js loaders which I found are about parallelizing and making faster in broadband environments on clustered load-balanced webservers, but I need serializing and reliability on a tiny 8bit MCU with webserver. 我发现的所有js加载器都是关于在群集负载平衡的Web服务器上的宽带环境中并行化和更快地进行的,但是我需要在带有Web服务器的小型8位MCU上进行序列化和提高可靠性。

Any hints or directions are appreciated! 任何提示或指示,不胜感激!

Edit: I have to apologize for using "socket" and "connection" interchangeably, I did mean "connection" and changed the original post accordingly. 编辑:我必须为互换使用“套接字”和“连接”表示歉意,我的意思是“连接”,并相应地更改了原始帖子。

The only way to reliably limit the number of connections a browser makes to your server is by only requiring a single connection to load everything in your page. 可靠地限制浏览器与服务器的连接数的唯一方法是仅需要单个连接即可加载页面中的所有内容。 In other words, everything must be inline. 换句话说,所有内容都必须是内联的。

<!DOCTYPE html>
<html><head><title>MCU app</title>
<link rel="shortcut icon" href="data:...">
<style>
    /* css here */
</style>
<script>
   // JS here
</script>
</head>
<body>

</body>
</html>

Of course, watch out for <img> tags. 当然,请注意<img>标签。

The other option I'd consider is hosting your HTML/JS/CSS/etc on a regular web server, and making only API calls to the embedded device. 我考虑的另一种选择是将HTML / JS / CSS / etc托管在常规的Web服务器上,并且仅对嵌入式设备进行API调用。

For example, you'd open mycoolembeddedapp.com in your browser. 例如,您将在浏览器中打开mycoolembeddedapp.com The app could ask for the embedded device's IP address, and then make AJAX calls to that IP using CORS. 该应用可能会询问嵌入式设备的IP地址,然后使用CORS对该IP进行AJAX调用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM