Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22441

Re: Compressing js file?

From wolfgang zeidler <invalid@invalid.invalid>
Newsgroups comp.lang.javascript
Subject Re: Compressing js file?
Date 2013-12-27 22:33 +0100
Organization (posted via) M-net Telekommunikations GmbH
Message-ID <l9krnd$ppg$1@news.m-online.net> (permalink)
References <l9a32q$vkf$1@speranza.aioe.org>

Show all headers | View raw


emf wrote:
> [...]
 >
> The size of the ephemeris.js with only 2 planets is 1,606 KB. It
> includes the ephem array that is in the form:
>
> var ephem = [["19000101","27i43","10i08"], ["19000102","27i50","10i12"], ... ];
>
>  [...]
>
> My question is: Is there a way to make the data file smaller and still
> be able to read it with the JavaScript program?

++--------------------------------------++
||   saving bytes for "19000101" etc.   ||
++--------------------------------------++

[A]:
var ephem = [[19000101,"27i43","10i08"], [...
and replacing calls like
   x = ephem [n] [0]
with
   x = ephem [n] [0] . toString ()
should save ~ 6.5%.

[B]:
var ep_off = 19000000
var ephem = [[101,"27i43","10i08"], [...
and replacing calls like
   x = ephem [n] [0]
with
   x = ( ep_off + ephem [n] [0] ) . toString ()
should save more than 20%.

[C], assuming ephem [n] [0] always
      contains the date ( 1900/01/01 + n days ):
Replace calls like
   x = ephem [n] [0]
with
   x = ephem_func_0 ( n )
with an easy_to_write-function ephem_func_0.
You won't need the first column of ephem furthermore
and you will save ~ 35%.


++--------------------------------------------++
||   saving bytes for "27i43","10i08"" etc.   ||
++--------------------------------------------++

[A], imho a little dirty way to write code
      ( but sometimes done by me ):
var ephem = [19000101,"27i43","10i08", 19000102,...
Replace calls like
   x = ephem [n] [0]
   y = ephem [n] [m]  // m > 0
with
   x = ephem [n*3]
   y = ephem [n*3+m]
and save ~ 6.5%.

[B], imho a _very_ dirty way to write code:
var ephem = [19000101,"27i4310i08", 19000102,...
Replace calls like
   x = ephem [n] [0]
   y = ephem [n] [1]
   z = ephem [n] [2]
with
   x = ephem [n*2]  // or ephem [n<<1] to avoid multiplikation
   y = ephem [n*2+1] . substr ( 0 , 5 )
   z = ephem [n*2+1] . substr ( 5 , 5 )
and save ~ 16.5%.

[C]:
if ( you don't need all rows of ephem at once or
      you don't need all columns of ephem at once )
and there is an easy way to calculate ephem [n] [m]
replace calls like
   y = ephem [n] [m]  // m > 0
with
   y = ephem_func_m ( n )
and save a lot of bytes.

>
> Thanks,
>
> Eustace
>
> PS. I remember that last time I visited the newsgroup, more than 1 year
> ago, it was more active. Where have all the other programmers gone?
>

Regards, Wolfgang,

-- 
http://wzwz.de/mail

---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compressing js file? emf <emfril@gmail.com> - 2013-12-23 14:31 -0500
  Re: Compressing js file? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-23 22:08 -0200
  Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-12-23 16:40 -0800
    Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-24 13:23 -0500
    Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-26 21:56 -0500
      Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 09:52 +0100
        Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-27 08:18 -0500
          Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 16:59 +0100
            Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-27 15:32 -0500
              Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 15:12 -0500
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 02:17 -0500
        Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-28 20:20 +0000
      XHR with timing issues (was: Compressing js file?) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-27 22:33 +0100
        Re: XHR with timing issues (was: Compressing js file?) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-27 23:26 +0100
          Re: XHR with timing issues Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-28 12:08 +0100
            Re: XHR with timing issues emf <emfril@gmail.com> - 2013-12-28 09:04 -0500
  Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-27 22:33 +0100
    Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 00:16 -0500
      Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-28 11:13 +0100
        Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 11:26 -0500
          Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 13:53 -0500
            Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-28 21:00 +0100
              Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-29 21:47 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-12-31 14:05 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 02:50 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 01:16 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 08:13 -0500
                Re: Compressing js file? Tim Streater <timstreater@greenbee.net> - 2014-01-01 14:17 +0000
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 15:31 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 18:38 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 15:45 -0800
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-02 11:43 -0500
                Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-02 09:34 -0800
                OT: Compressing js file? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-02 19:52 +0100
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-03 07:19 -0500
                Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-03 07:31 -0500
                Re: Compressing js file? Tim Streater <timstreater@greenbee.net> - 2014-01-02 09:14 +0000
                Re: Compressing js file? Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-01 16:25 +0000
                Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-01 21:36 +0100
          Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-29 20:06 +0100
            Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-29 20:27 +0100
        Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-29 18:02 +0000
          Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-30 18:17 +0100
            Re: Compressing js file? John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-31 10:52 +0000
            Re: Compressing js file? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-31 13:38 +0000
              Re: Compressing js file? John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-31 15:02 +0000
                Re: Compressing js file? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-01 16:42 +0000
                Re: Compressing js file? Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-01 21:32 +0000
            Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-31 21:44 +0000

csiph-web