Make the Jalan Sehat coupon page smooth on cheap phones: debounce, workers, virtual lists, srcset. 16 levels, right in the browser.
What the levels ask
Mr. Ilham built the Kupon Jalan Sehat page: a villager types their name and their coupon appears. On the cheap test phone each search takes about 90 ms. Mrs. Sari types her mother's name, sumarsih. Pick the input handler in cari.js so the page searches once, for the whole name, after Mrs. Sari stops typing.
The header of the 5,000-coupon list shows the coupon under the finger, worked out by kuponDi, which goes through 5,000 coupons every time. Bagas scrolls the list as hard as he can. Pick the scroll handler in gulir.js so the header keeps changing while the finger moves, but is not worked out on every scroll event.
The draw's drum of numbers spins on the phone until the neighbourhood head stops it, and Rara watches. Pick how putar is scheduled in putar.js so each frame of the screen draws exactly one new position: no frame standing still, no position written and thrown away.
The neighbourhood head opens last year's winners board: 300 cards, each with a ribbon as wide as its winner's name. On the test phone the board appears only after the phone sits still a long time. Pick how papan.js measures and writes the ribbons' widths so the browser lays out only once.
The Cek kuponku button checks 5,000 coupons, about a second on the test phone. Grandma Marni taps it, the screen sits still, and she taps again and again. Fill in the start of the click handler in cek.js so Mencari kuponmu... is drawn on screen right after the tap, before the check runs.
The coupon check now runs in pieces: after a number of coupons, cek.js waits for a frame. Mr. Tono taps Cek kuponku, then right away Lihat hadiah. Pick the size of a piece so the second tap is answered quickly, and the check still finishes not much later than its own work takes.
Villagers can recompute the draw's winners on their own phones from the seed the neighbourhood head announces. hitungUndian is one heavy function that cannot be split from outside. Mr. Bayu taps Hitung ulang undian, then Lihat hadiah. Fill in the call in hitung.js so the page keeps drawing and answering taps while the draw is computed.
A team's costume photo is 2048 x 1536 pixels, 12 MB in memory, and is shrunk in a Web Worker before upload. The test phone is short of memory, so two 12 MB copies are dangerous. Fill in the send in foto.js so there is only one copy of the photo and its preview is still drawn on screen.
The 5,000-coupon list now makes only the rows in view: gambar() in daftar.js fills the isi box starting at the row at the scroll position. Mr. Harun has a tall phone (360 x 780). Fill in jumlah so the screen is always full with no empty space, with as few rows as possible, on a phone of any height.
Bagas flings the list: hundreds of pixels a frame. New rows are made only after the scroll position changes, so the screen sometimes shows empty for a moment. Pick LEBIH, the number of spare rows above and below the screen, so the screen is never empty during the fling, without making hundreds of rows nobody ever sees.
The route map is 3200 pixels wide (rute-3200.jpg), yet on Mrs. Yanti's phone it shows 360 CSS pixels wide. There are also 480, 960 and 1440 pixel versions. Fill in srcset in index.html so the browser itself picks a file sharp enough for that phone's screen, without downloading pixels it cannot show.
The gallery of last year's fun walk: 24 photos in three columns, each about 107 CSS pixels on a phone. The srcset is already there, from 160 to 1440 pixels. But Ms. Wulan's data goes on photos the size of the screen. Fill in sizes so the browser picks files for the column's real width.