Home > Web Front-end > JS Tutorial > JavaScript Loader

JavaScript Loader

Barbara Streisand
Release: 2024-11-03 11:44:03
Original
781 people have browsed it

Loaders are transformations that are applied to the source code of a module or a script. They allow you to pre-process files or html with javascript inside as you import or “load” them. Thus, loaders are kind of like “tasks” in other build tools and provide a powerful way to handle front-end build steps.
The idea is to download a JS programm and run it native locally in a runtime browser (webview2) with some modifications in it, based on a script you deliver before. I call this a multiple deployment as a fixture:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

const

  SINWAVES2URL= 'https://raw.githack.com/maxkleiner/maXbox4/master/assets/sinwavesjs.html';

aMS:= TMemoryStream.Create;

 try

   HttpGet(SINWAVES2URL, amS)

   writeln('urlcontent size: '+itoa((ams.size)));

   aMS.Seek(0, 0);

   memoHTML.lines.loadfromstream(aMs);

   //javascript fixture_

   memoHTML.text:= StringReplace(memoHtml.text,'frequency = 20;','frequency = 30;',[rfReplaceAll]);

   memoHTML.text:= StringReplace(memoHtml.text,'Sine Wave</h3>','Sine Wave F30</h3>',[rfReplaceAll]);

   navigatetoString(memoHTML.text);

 finally

   aMS.Free

 end;

Copy after login

For example, you can use loaders to tell a website to load a CSS with javascript file and to modify parameters in JavaScript before you run it in a local browser webview2.

JavaScript Loader

Loaders can be chained. Each loader in the chain applies transformations to the processed resource for example load the url as a stream in a memo with lines, modify two parameters (frequency and title in our example) an run it with navigatetoString(memoHTML.text); on a browser:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

with TEdgeViewForm.create(self) do begin

   PageControl1.ActivePageIndex := 1;

   edit1.text:= SINWAVES2URL;

   aMS:= TMemoryStream.Create;

   try

     HttpGet(SINWAVES2URL, amS)

     writeln('urlcontent size: '+itoa((ams.size)));

     aMS.Seek(0, 0);

     memoHTML.lines.loadfromstream(aMs);

     //javascript fixture_

     memoHTML.text:= StringReplace(memoHtml.text,'frequency = 20;','frequency = 30;',[rfReplaceAll]);

     memoHTML.text:= StringReplace(memoHtml.text,'Sine Wave</h3>','Sine Wave F30</h3>',[rfReplaceAll]);

     navigatetoString(memoHTML.text);

   finally

     aMS.Free

   end;   

   showmodal

   free;

 end

Copy after login

The above is the detailed content of JavaScript Loader. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template