Atozed Forums

Full Version: Optimization of final HTML code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have IntraWeb 15.1.20 Ultimate with source code (Subscription to 2021).

Is it possible to optimize final HTML code? (I would like to remove characters #9 and #13#10)

I'm trying with WebApplication.Response in the IWUserSessionBaseAfterExecuteForm event, but I can't get to ContentStream.

Probably only solution is to add something to source code.
What's the reason for that?

Believe me, whatever feeling you may have that it will improve things don't hold against any performance test.

Even the fastest text parser on earth is not able to remove enough chars from it to a point that it will be faster to parse/optimize/transmit than increasing your compression ratio in ServerController.Compression.Level setting.

One example:

I ran a random IW project which is open now on my IDE. Size of the HTML:

Original: 3316
Optimized (using online HTML minifier): 2718
Gain = 18%

Now, I gzipped both using maximum compression:
Original: 1,456 (1,466 using fastest)
Optimized: 1,324 (1,329 using fastest)

The difference is now only 9%. Also notice that using fastest compression I get almost exactly the same result. Have in mind that fastest compression, especially in x64 uses extra-optimized Cloudflare gzip compression which is the fastest available in the (Delphi) world.

The difference tends to be smaller when the file size increases (~ 5-7%). Whatever performance gain you may think you will have with, say, 10% of reduction of the traffic will be
pulverized by the CPU cycles spent by the parser/optimizer.
I wasn't exactly about optimizations, but about "look".
In IntraWeb, IWBase__*.js or IWGecko __ *. Js file looks great.
I would like the main html code to be more "unreadable" (it gives a little professional look).

In my old Indy HTTP Server projects I used this simple code:

Code:
function OptimizeCode(const data: string): string;
var opt: TStringList; i: integer;
begin
Result := '';
opt := TStringList.Create;
opt.Text := StringReplace(data, #9, '', [rfReplaceALL]);
for i := 0 to opt.Count - 1 do Result := Result + opt.Strings[i];
opt.Free;
end;

For now, In IntraWeb I only use code to delete generator information:

Code:
procedure TIWServerController.IWServerControllerBaseMetaTag(
  ASession: TIWApplication; const AMetaName: string; var vMetaValue: string);
begin
if AnsiLowerCase(AMetaName) = 'generator' then vMetaValue := '';
end;

But this optimization code could still be useful.
You may want to obfuscate your js code during build. That also means you only do it once, and none at runtime.

For changing/killing the "generator" string, there is an event for that. See IWServerControllerBaseMetaTag()

Dan
(04-24-2020, 09:14 PM)DanBarclay Wrote: [ -> ]You may want to obfuscate your js code during build.  That also means you only do it once, and none at runtime.

For changing/killing the "generator" string, there is an event for that.  See IWServerControllerBaseMetaTag()

Dan

Yes, I know how to do it, see my last post.
This is the only thing I can do now to improve my html code.

It works but...
I still need to write the html code in one line.

For example.
Normal html code:
Code:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>



<link href="/$/css/IWNotify__2753029400.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" nonce="4V82b6g5AalSsGNFvKJsVWTxuvc">
var GURLBase="/TPtuF1zNx6pQVhHlIxAcVLgaFp8/$/", GAppID="i1QKDuL3x5dX0ZvnGSfrEsr-trC", GTrackID=1;
function doOnReady(f){
   var d = document;
   if (d.readyState!="loading") f();
   else if (d.addEventListener) d.addEventListener("DOMContentLoaded", f);
   else d.attachEvent("onreadystatechange", function(){if (d.readyState=="complete") f();})
}
</script>
<script type="text/javascript" src="/$/js/IWBase__2847485697.js"></script>
<script type="text/javascript" src="/$/js/IWGecko__1086946337.js"></script>
<script type="text/javascript" nonce="4V82b6g5AalSsGNFvKJsVWTxuvc">
function Body_OnBlur(){GSubmitting = false;}
function FormDefaultSubmit(event){return false;}
function IWTop(){return window;}
function Validate() {
  return true;
}

(...)

</script></body></html>

Code optimized in one line with my simple function:
Code:
<!DOCTYPE HTML><html lang="en"><head><meta charset="utf-8"><title></title><link href="/$/css/IWNotify__2753029400.css" rel="stylesheet" type="text/css"/><script type="text/javascript" nonce="4V82b6g5AalSsGNFvKJsVWTxuvc">var GURLBase="/TPtuF1zNx6pQVhHlIxAcVLgaFp8/$/", GAppID="i1QKDuL3x5dX0ZvnGSfrEsr-trC", GTrackID=1;function doOnReady(f){   var d = document;   if (d.readyState!="loading") f();   else if (d.addEventListener) d.addEventListener("DOMContentLoaded", f);   else d.attachEvent("onreadystatechange", function(){if (d.readyState=="complete") f();})}</script><script type="text/javascript" src="/$/js/IWBase__2847485697.js"></script><script type="text/javascript" src="/$/js/IWGecko__1086946337.js"></script><script type="text/javascript" nonce="4V82b6g5AalSsGNFvKJsVWTxuvc">function Body_OnBlur(){GSubmitting = false;}function FormDefaultSubmit(event){return false;}function IWTop(){return window;}function Validate() {  return true;}(...)</script></body></html>

I just need this simple optimization.

Is it possible to use my code for optimization or something similar?