From eb642bd38dc1a8ef49463b1f2767db3b89d25f81 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 15 Aug 2023 09:57:57 +0100 Subject: [PATCH] Reduce initial load time for the browse page by only loading authority names, not full geojson --- assets/README.md | 6 ++++++ assets/authority_names.json | 1 + src/pages/BrowseSchemes.svelte | 25 ++++++++++--------------- 3 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 assets/authority_names.json diff --git a/assets/README.md b/assets/README.md index 3ceb86c7b..c42085e13 100644 --- a/assets/README.md +++ b/assets/README.md @@ -1 +1,7 @@ Material Icons courtesy https://fonts.google.com/icons + +`authority_names.json` is generated from `authorities.geojson` like this: + +``` +cat assets/authorities.geojson | jq '.features[].properties.name' | sort | jq -cs '.' > assets/authority_names.json +``` diff --git a/assets/authority_names.json b/assets/authority_names.json new file mode 100644 index 000000000..a16f2488e --- /dev/null +++ b/assets/authority_names.json @@ -0,0 +1 @@ +["Adur","Allerdale","Amber Valley","Arun","Ashfield","Ashford","Babergh","Barking and Dagenham","Barnet","Barnsley","Barrow-in-Furness","Basildon","Basingstoke and Deane","Bassetlaw","Bath and North East Somerset","Bedford","Bexley","Birmingham","Blaby","Blackburn with Darwen","Blackpool","Bolsover","Bolton","Boston","Bournemouth, Christchurch and Poole","Bracknell Forest","Bradford","Braintree","Breckland","Brent","Brentwood","Brighton and Hove","Bristol, City of","Broadland","Bromley","Bromsgrove","Broxbourne","Broxtowe","Buckinghamshire","Burnley","Bury","Calderdale","Cambridge","Cambridgeshire and Peterborough Combined Authority","Camden","Cannock Chase","Canterbury","Carlisle","Castle Point","Central Bedfordshire","Charnwood","Chelmsford","Cheltenham","Cherwell","Cheshire East","Cheshire West and Chester","Chesterfield","Chichester","Chorley","City of London","Colchester","Copeland","Cornwall","Cotswold","County Durham","Coventry","Craven","Crawley","Croydon","Cumbria","Dacorum","Darlington","Dartford","Derby","Derbyshire","Derbyshire Dales","Devon","Doncaster","Dorset","Dover","Dudley","Ealing","Eastbourne","East Cambridgeshire","East Devon","East Hampshire","East Hertfordshire","Eastleigh","East Lindsey","East Riding of Yorkshire","East Staffordshire","East Suffolk","East Sussex","Eden","Elmbridge","Enfield","Epping Forest","Epsom and Ewell","Erewash","Essex","Exeter","Fareham","Fenland","Folkestone and Hythe","Forest of Dean","Fylde","Gateshead","Gedling","Gloucester","Gloucestershire","Gosport","Gravesham","Greater London","Greater Manchester Combined Authority","Great Yarmouth","Greenwich","Guildford","Hackney","Halton","Hambleton","Hammersmith and Fulham","Hampshire","Harborough","Haringey","Harlow","Harrogate","Harrow","Hart","Hartlepool","Hastings","Havant","Havering","Herefordshire","Herefordshire, County of","Hertfordshire","Hertsmere","High Peak","Hillingdon","Hinckley and Bosworth","Horsham","Hounslow","Huntingdonshire","Hyndburn","Ipswich","Isle of Wight","Isles of Scilly","Islington","Kensington and Chelsea","Kent","King's Lynn and West Norfolk","Kingston upon Hull","Kingston upon Hull, City of","Kingston upon Thames","Kirklees","Knowsley","Lambeth","Lancashire","Lancaster","Leeds","Leicester","Leicestershire","Lewes","Lewisham","Lichfield","Lincoln","Lincolnshire","Liverpool","Liverpool City Region Combined Authority","Luton","Maidstone","Maldon","Malvern Hills","Manchester","Mansfield","Medway","Melton","Mendip","Merton","Mid Devon","Middlesbrough","Mid Suffolk","Mid Sussex","Milton Keynes","Mole Valley","Newark and Sherwood","Newcastle-under-Lyme","Newcastle upon Tyne","New Forest","Newham","Norfolk","North Devon","North East Derbyshire","North East Joint Transport Committee","North East Lincolnshire","North Hertfordshire","North Kesteven","North Lincolnshire","North Norfolk","North Northamptonshire","North Somerset","North Tyneside","Northumberland","North Warwickshire","North West Leicestershire","North Yorkshire","Norwich","Nottingham","Nottinghamshire","Nuneaton and Bedworth","Oadby and Wigston","Oldham","Oxford","Oxfordshire","Pendle","Peterborough","Plymouth","Portsmouth","Preston","Reading","Redbridge","Redcar and Cleveland","Redditch","Reigate and Banstead","Ribble Valley","Richmondshire","Richmond upon Thames","Rochdale","Rochford","Rossendale","Rother","Rotherham","Rugby","Runnymede","Rushcliffe","Rushmoor","Rutland","Ryedale","Salford","Sandwell","Scarborough","Sedgemoor","Sefton","Selby","Sevenoaks","Sheffield","Sheffield City Region Combined Authority","Shropshire","Slough","Solihull","Somerset","Somerset West and Taunton","Southampton","South Cambridgeshire","South Derbyshire","Southend-on-Sea","South Gloucestershire","South Hams","South Holland","South Kesteven","South Lakeland","South Norfolk","South Oxfordshire","South Ribble","South Somerset","South Staffordshire","South Tyneside","Southwark","Spelthorne","Stafford","Staffordshire","Staffordshire Moorlands","St Albans","Stevenage","St. Helens","Stockport","Stockton-on-Tees","Stoke-on-Trent","Stratford-on-Avon","Stroud","Suffolk","Sunderland","Surrey","Surrey Heath","Sutton","Swale","Swindon","Tameside","Tamworth","Tandridge","Tees Valley Combined Authority","Teignbridge","Telford and Wrekin","Tendring","Test Valley","Tewkesbury","Thanet","Three Rivers","Thurrock","Tonbridge and Malling","Torbay","Torridge","Tower Hamlets","Trafford","Tunbridge Wells","Uttlesford","Vale of White Horse","Wakefield","Walsall","Waltham Forest","Wandsworth","Warrington","Warwick","Warwickshire","Watford","Waverley","Wealden","Welwyn Hatfield","West Berkshire","West Devon","West Lancashire","West Lindsey","West Midlands ITA","Westminster","West Northamptonshire","West of England Combined Authority","West Oxfordshire","West Suffolk","West Sussex","West Yorkshire Combined Authority","Wigan","Wiltshire","Winchester","Windsor and Maidenhead","Wirral","Woking","Wokingham","Wolverhampton","Worcester","Worcestershire","Worthing","Wychavon","Wyre","Wyre Forest","York"] diff --git a/src/pages/BrowseSchemes.svelte b/src/pages/BrowseSchemes.svelte index e0c87a49b..e640fcf25 100644 --- a/src/pages/BrowseSchemes.svelte +++ b/src/pages/BrowseSchemes.svelte @@ -4,6 +4,7 @@ import "../style/main.css"; import type { MapGeoJSONFeature } from "maplibre-gl"; import { onDestroy, onMount } from "svelte"; + import authorityNamesList from "../../assets/authority_names.json"; import BusRoutesLayerControl from "../lib/browse/BusRoutesLayerControl.svelte"; import CensusOutputAreaLayerControl from "../lib/browse/CensusOutputAreaLayerControl.svelte"; import CombinedAuthoritiesLayerControl from "../lib/browse/CombinedAuthoritiesLayerControl.svelte"; @@ -30,7 +31,6 @@ MapLibreMap, ZoomOutMap, } from "../lib/common"; - import { getAuthoritiesGeoJson } from "../lib/common/data_getter"; import PmTiles from "../lib/common/PmTiles.svelte"; import InterventionLayer from "../lib/draw/InterventionLayer.svelte"; import { CheckboxGroup, ErrorMessage, SecondaryButton } from "../lib/govuk"; @@ -40,14 +40,11 @@ import type { Scheme as GjScheme } from "../types"; // TODO Remove after the input data is fixed to plumb correct authority names. - let authorityNames: Set | null = null; + let authorityNames: Set = new Set(authorityNamesList); - onMount(async () => { + onMount(() => { // For govuk components. Must happen here. initAll(); - - let geojson = await getAuthoritiesGeoJson(); - authorityNames = new Set(geojson.features.map((f) => f.properties!.name)); }); const params = new URLSearchParams(window.location.search); @@ -123,15 +120,13 @@ {/if} - {#if authorityNames} -
    - {#each schemes.values() as scheme} - {#if schemesToBeShown.has(scheme.scheme_reference)} - - {/if} - {/each} -
- {/if} +
    + {#each schemes.values() as scheme} + {#if schemesToBeShown.has(scheme.scheme_reference)} + + {/if} + {/each} +