Reduce loading time with a compressed library environment

Share your advanced knowledge/code with the community.
Stefan Schnell
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am
Contact:

Reduce loading time with a compressed library environment

Post by Stefan Schnell »

Hello community,

the javascript directory of SpiderBasic contains a lot of JS- and CSS-files. I checked the loading time of the 2ddrawing-example via GTmetrix (http://gtmetrix.com) and in the result table are the suggestion to compress the JS- and CSS-files to reduce the loading time. I look for a JS/CSS-compressor for the Windows environment and I found Microsofts Ajax Minifier (http://ajaxmin.codeplex.com). AjaxMin is a command line tool. To feed AjaxMin I code a PowerShell script and this creates a batch file.

Code: Select all

#-Begin-----------------------------------------------------------------

  $Content = ""

  #-Get all JavaScript files--------------------------------------------
    $Files = Get-ChildItem . -Filter "*.js" -Recurse
    $Files | ForEach-Object {
      $Line = "AjaxMinifier.exe -JS """ + $_.FullName + """ -out """ +
        $_.FullName + """"
      $Content += $Line + "`r`n"
    }

  #-Get all Cascading Style Sheet files---------------------------------
    $Files = Get-ChildItem . -Filter "*.css" -Recurse
    $Files | ForEach-Object {
      $Line = "AjaxMinifier.exe -CSS """ + $_.FullName + """ -out """ +
        $_.FullName + """"
      $Content += $Line + "`r`n"
    }

  #-Write the batch file------------------------------------------------
    New-Item . -Name Min.bat -Type "File" -Value $Content -Force

  #-Delete all LICENSE and README.md files------------------------------
    $Files = Get-ChildItem . -Include "LICENSE", "README.md" -Recurse
    $Files | ForEach-Object {
      Remove-Item $_.FullName
    }

#-End-------------------------------------------------------------------
Copy this script in a copy of the javascript directory and run it. Move the Min-batch file to AjaxMin program and run it. After that the size of the directory is reduced by 48,5%. I copy this javascript directory in my production environment and the loading time is speed up by 10%. :mrgreen:

Enjoy it.

Cheers
Stefan
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Reduce loading time with a compressed library environmen

Post by Fred »

that's great trick !
Stefan Schnell
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am
Contact:

Re: Reduce loading time with a compressed library environmen

Post by Stefan Schnell »

Hello community,

here tiny addendum to disable null bytes files:

Code: Select all

  #-Add CrLf to null length files---------------------------------------
    $Files = Get-ChildItem . -Recurse | Where-Object {$_.Length -eq 0}
    $Files | ForEach-Object {
      Add-Content $_.FullName ""
It is not possible to upload files with null bytes e.g. in the SAP MIME repository, otherwise you get an error.

Hint: The actual release of SpiderBasic loose 43.5 % of space with this method.

Enjoy it.

Cheers
Stefan
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Reduce loading time with a compressed library environmen

Post by Fred »

I have just patched the empty files as well, so it will work out of the box with SAP
Stefan Schnell
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am
Contact:

Re: Reduce loading time with a compressed library environmen

Post by Stefan Schnell »

Hello Fred,

thank you very much :D

Cheers
Stefan
Post Reply