From a5754eb95c64317ffbc10a48e199c8a3c238a34a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 5 Mar 2026 13:44:36 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Remove=20object=20serializa?= =?UTF-8?q?tion=20in=20DOM=20attributes=20for=20list=20rendering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MrAlokTech <107493955+MrAlokTech@users.noreply.github.com> --- .jules/bolt.md | 3 +++ script.js | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..98cc448 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - Avoid Object Serialization in DOM Attributes +**Learning:** During list rendering (`createPDFCard`), executing `JSON.stringify(object).replace(...)` to pass an entire object to an `onclick` inline handler creates massive performance overhead. Not only is serialization expensive, but it also generates huge string sizes in the DOM resulting in increased memory use. +**Action:** Instead of inline full-object serialization, pass a simple unique ID (`data-id="123"`) and rely on the event handler (`viewPDF(id)`) to look up the object reference in the data store (`pdfDatabase`). diff --git a/script.js b/script.js index bdc06f3..2b2a10f 100644 --- a/script.js +++ b/script.js @@ -788,7 +788,13 @@ function getEmbeddableUrl(url) { return `https://docs.google.com/gview?embedded=true&url=${encodeURIComponent(url)}`; } -async function viewPDF(pdf, pushToHistory = true) { +async function viewPDF(pdfOrId, pushToHistory = true) { + let pdf = pdfOrId; + if (typeof pdfOrId === 'string') { + pdf = pdfDatabase.find(p => p.id === pdfOrId); + } + if (!pdf) return; + const originalPdfPath = pdf.pdfUrl; logInteraction('view_pdf', pdf.title, pdf.id); @@ -1020,7 +1026,8 @@ function createPDFCard(pdf, favoritesList, index = 0, highlightRegex = null) { return safeText.replace(highlightRegex, '$1'); }; - const safePdfString = JSON.stringify(pdf).replace(/"/g, '"'); + // ⚡ Bolt Performance Optimization: Removed expensive JSON.stringify(pdf) which was running for every card. + // Now we just pass the PDF ID and let viewPDF handle the lookup. // --- NEW: Calculate Stagger Delay --- // Cap at 1s (20 items) so the list doesn't feel unresponsive @@ -1037,7 +1044,7 @@ function createPDFCard(pdf, favoritesList, index = 0, highlightRegex = null) {

${highlightText(pdf.description)}

-