[Pas2js] Progressive Web Apps

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Nov 10 09:21:32 CET 2018


On Fri, 9 Nov 2018 13:25:02 +0000
"Ulrich, Christian" <christian.ulrich at tcsag.de> wrote:

The other thread was about a "variable in the .LPR file so that
it can be used by all the units in the project".
PWA is a different topic.

> I must execute code as fast as possible after loading the index
> (Progressive Web Apps must install an handler to handle
> caching/updates of the page to be able to handle offline requests
> right) And I want to do that before loading the rtl js and my
> librarys and so on and naturally long before rtl.run is called

Note that you can use -JiYourStartCode.js -Jirtl.js to insert
YourStartCode.js before the rtl.js.

If the callback references some Pascal code then you can do the
following:

program project1;

{$mode objfpc}

uses
  browserapp, JS, Classes, SysUtils, Web;

type
  TMyApplication = class(TBrowserApplication)
    procedure doRun; override;
  end;

procedure TMyApplication.doRun;

begin
  // Your code here
  Terminate;
end;

function Run(Event: TEventListenerEvent): boolean;
var
  Application : TMyApplication;
begin
  Application:=TMyApplication.Create(nil);
  Application.Initialize;
  Application.Run;
  Application.Free;
  Result:=true;
end;

begin
  // add callbacks for PWA
  // ...
  // delay starting the application
  window.addEventListener('load', @Run);
end.

 
> But it would be nice to be able to handle the caching Stuff in an
> Pascal class and just injecting the installation of the handlers in
> asm in the same unit

Can you give an example for such a handler?


Mattias


More information about the Pas2js mailing list