2

I am writing a Media-HUD that runs totally on local notecard files stored within the prim's inventory, with notecards named like index.html, style.css, icon.svg etc.

My hope is to use the LSL HttpServer functions, and the script's URL to create a totally self-contained media based HUD that is easy to edit like editing any web page.

This is completely possible on its own, however there is a limitation in that, the pages must fit into the memory allocated to the LSL script. Under mono this is only 64kb.

I want to remove this limitation, by somehow, perhaps from javascript, reading in each 'file' from a notecard line by line in the users browser itself (thusly, getting around the memory limit by only bringing one notecard line into memory at a time).

Is there a way to do this? generate a entire file in javascript procedurally by loading in the strings making it up line by line, and then serve it as though it were a whole file? I'm not sure how feasible this is.

Any idea's/guidance greatly appreciated!

Thomas Harris
  • 573
  • 4
  • 14
  • 1
    Thanks for your help everyone. In the end I decided to create a bunch of 'memory bank' scripts, one for each notecard. The reason I did this was that reading in a notecard line by line is _slow_ and having all the data there in memory was the only way to keep things responsive. – Thomas Harris Mar 30 '18 at 21:26

2 Answers2

3

You could do this through Javascript using XMLHttpRequest. jQuery's wrapper for this is called Ajax. You could request each line individually, which would be slightly slower, or read in a number of lines at a time, at the script's leisure. http_request is not throttled so either works. Note that the loader has to be sent in a single response, because the LSL server has no way of pushing data "piecemeal" like an actual server does.

Notes:

  • llGetNotecardLine only returns the first 255 bytes per line.
  • llHTTPResponse must be called within ~20 seconds of the request, so you can't feasibly read more than 20 lines from a notecard at a time.
  • I'm not sure how this would work for non-DOM filetypes. All files would need to be embed-able in the HTML using the Javascript DOM. To my knowledge, Javascript can't arbitrarily create an external file and serve it to itself. Obviously it would not work for non-text filetypes, but you could certainly load in the rest of the HTML, CSS, and HTML5 SVG. Basically, if it can go in a single HTML file, you could load it in through Javascript.

I have no experience with React but it gives a good example of what is possible on the UI side with loading things in purely through Javascript.

Alex
  • 151
  • 3
2

So less than 64 thousand characters in memory at most per script. I will give you some advise that might make your task feasable:

External resources

Minimize the amount of code you have to have in your notecards by sourcing popular libraries from the web Bootstrap, React and such. You will have to rely on their mirror's availability thought. But it will greatly reduce the amount of memory needed to provide pretty and functional pages.

Minify your code

Use tools like Uglify or Closure Compiler to make your javascript lighter. Though you must be careful, as these tools will fit all your code a single long line by the default, and you can't read lines longer than 255 characters with LSL. Luckily you can customize your options in these tools to limit the amount of characters per line.

Divide and conquer

Since a single script can't handle much memory, make dedicated scripts. One could serve resources (act as a file server, providing your html and js) while the other would receive API request calls, to handle the application's logic.

Agesly Danzig
  • 81
  • 1
  • 3