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

ぃ、小莉子 提交于 2019-12-11 18:18:26

问题


I want to create a networked embedded device with an HTML5/JS one-page AJAX configuration application.

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).

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.

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).

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.

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.


回答1:


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.

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.

For example, you'd open mycoolembeddedapp.com in your browser. The app could ask for the embedded device's IP address, and then make AJAX calls to that IP using CORS.



来源:https://stackoverflow.com/questions/11906900/is-there-a-javascript-loader-which-can-limit-the-number-of-sockets-to-1-or-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!