Script Templates
The Script component wraps the RectPy html.script() to provide support for variable substitution and minification.
Script example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Minification¶
The minimal minification process will, if enabled, strip white space, comments and console.log() messages from the source. The minification process is pretty dumb. Semicolons at the end of statements are important. If your script fails when minified check first for missing semicolons.
Script Life Cycle¶
Scripts are injected and run when the associated page is loaded. If the script hooks into event listeners or other state-related aspects of the DOM then these must be un-hooked when the page is destroyed. This can be achieved by returning a page-unload function reference when the script is first loaded. To do this define a script with the following pattern:
1 2 3 4 5 6 7 8 9 10 11 |
|
Debugging Scripts¶
Scripts can be debugged using the Browser debugger (or directly in VSCODE). To locate the code add a console.log("My Code Loaded")
message to the script. This will appear in the debugger console window. Clicking on it will take you directly to your code. Add brake points as required.