vsolina / micropython-web-editor

Web-based code editor (IDE) for MicroPython controllers with WiFi
MIT License
26 stars 4 forks source link

How to store ace.js files on Controller's flash #5

Open casainho opened 1 year ago

casainho commented 1 year ago

When using the IDE, Internet connection is required because Ace is hosted on cdnjs (to reduce storage requirements); but it's possible to bundle required ace.js files on Controller's flash (raise an Issue and I'll explain how to do it)

I wish to have everything local, as I am using an ESP32 with a LOT of memory that I do not use.

vsolina commented 1 year ago

This requires a bit of effort (for now). In order to host ace.js files on the controller, a single change to weditor/index.html is necessary: line 12. which loads ace.js:

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.11.2/ace.js" type="text/javascript" charset="utf-8"></script>

needs to be changed to:

<script src="js/ace.js" type="text/javascript" charset="utf-8"></script>

Finally ace.js files need to be uploaded to controller into weditor/js/ directory. There are mandatory files (without them everything breaks):

And optional files:

All of these files are available here (v1.14.0): https://github.com/ajaxorg/ace-builds/tree/62b5377d9d115313fc07dc74926b292cc7683497/src Or better, minified versions here (smaller files, faster load times): https://github.com/ajaxorg/ace-builds/tree/62b5377d9d115313fc07dc74926b292cc7683497/src-min

casainho commented 1 year ago

Please link this information on the main README.

gitcnd commented 1 year ago

If you want to gzip-compress the ace.js file (makes it 117179 instead of 439253 bytes) you can use my MicroWebSrv.py from https://github.com/gitcnd/MicroWebSrv

OR better - use https://github.com/gitcnd/MicroWebSrv/blob/master/microWebSrv-min.py (but name it MicroWebSrv.py). save it as ace.js.gz and adjust index.html like this:-

<script src="js/ace.js.gz" type="text/javascript" charset="utf-8"></script>

(you can compress other web files too if you want - not .py of course though). Do not use brotli (gzip only) - brotli is only supported in browsers over HTTPS.

gitcnd commented 1 year ago

also, if you want to gzip all the ace files/dependencies, edit the ace.js file and find this text:

createElement("script");i.src=e",n.appendChild(i)

and change it to this:-

createElement("script");i.src=e+".gz",n.appendChild(i)