I recently had a large JavaScript array – a complex polygon of latitude and longitude coordinates.
The file was undesirably large (about 32 MB) which seemed to stem from the precision of the coordinates being up to 17 decimal places.
Fortunately, the simple yet powerful Notepad++ could help – by using the regex find and replace we can reduce the precision of the coordinates.
To do this,
- open the Replace dialogue (Ctrl + H)
- under ‘Search mode’ select ‘Regular expression’
- in ‘Find what’ enter the following
-
\d+\.\d{5}\K\d+
- leave ‘Replace with’ empty
This will reduce the precision down to 5 decimal places – change the 5 in step 4 for alternatives.
For me, this reduced the file from 32 MB to 15 MB – a massive saving that will result in a faster loading map.