<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 王康</title>
    <description>The latest articles on DEV Community by 王康 (@_cafda18cb1684fc076f294).</description>
    <link>https://dev.to/_cafda18cb1684fc076f294</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4181811%2F8d448d94-6696-484f-a225-67e4c70efb7e.jpg</url>
      <title>DEV Community: 王康</title>
      <link>https://dev.to/_cafda18cb1684fc076f294</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_cafda18cb1684fc076f294"/>
    <language>en</language>
    <item>
      <title>Image Compress Workflow: Check What the Browser Actually Download</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Wed, 25 Nov 2026 09:12:13 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/image-compress-workflow-check-what-the-browser-actually-download-pl3</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/image-compress-workflow-check-what-the-browser-actually-download-pl3</guid>
      <description>&lt;p&gt;You resize your hero photo, lower the JPEG quality, and ship three responsive versions. Then you open the page on a phone and discover that it still downloads the largest one. Before you touch the quality slider again, check &lt;code&gt;sizes&lt;/code&gt;: the browser might think the image takes up the whole screen when it actually sits in a narrow column.&lt;/p&gt;

&lt;p&gt;An image compression workflow has two jobs: make each file smaller, and make sure the browser picks a file that fits the layout. Here’s a small demo that lets you test those two decisions separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Export three versions from one source
&lt;/h2&gt;

&lt;p&gt;Use a landscape JPEG you own, ideally about 1800 × 1200 pixels. On macOS, put it in a new demo folder as &lt;code&gt;hero-original.jpg&lt;/code&gt;, then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p images

&lt;span class="k"&gt;for&lt;/span&gt; width &lt;span class="k"&gt;in&lt;/span&gt; 480 800 1200&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  sips --resampleWidth &lt;span class="s2"&gt;"$width"&lt;/span&gt; --setProperty format jpeg \
    --setProperty formatOptions 78 hero-original.jpg \
    --out &lt;span class="s2"&gt;"images/hero-${width}.jpg"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;

wc -c hero-original.jpg images/hero-*.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On another OS, export the same three widths with your usual image editor. The HTML doesn’t depend on the encoder. Here, &lt;code&gt;78&lt;/code&gt; is a starting point for a photograph, not a setting to reuse for every asset. Compare gradients and fine texture against the original. For screenshots with small text, compare PNG or lossless WebP before settling on JPEG.&lt;/p&gt;

&lt;p&gt;Keep the original. If a candidate looks rough, export it again from the source, not from the JPEG you already compressed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make &lt;code&gt;sizes&lt;/code&gt; match the layout
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;index.html&lt;/code&gt; next to the &lt;code&gt;images&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Responsive image demo&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.hero&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt; &lt;span class="n"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24px&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.hero&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;main&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hero"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Responsive image demo&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt;
    &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"images/hero-800.jpg"&lt;/span&gt;
    &lt;span class="na"&gt;srcset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"images/hero-480.jpg 480w,
            images/hero-800.jpg 800w,
            images/hero-1200.jpg 1200w"&lt;/span&gt;
    &lt;span class="na"&gt;sizes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"(max-width: 632px) calc(100vw - 32px), 600px"&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1200"&lt;/span&gt;
    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;
    &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"A mountain landscape reflected in a lake"&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adjust the &lt;code&gt;alt&lt;/code&gt; text and the aspect ratio in &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; to match your own photo. Each &lt;code&gt;w&lt;/code&gt; descriptor must match the file’s actual pixel width. The &lt;code&gt;sizes&lt;/code&gt; attribute doesn’t set the CSS width; it tells the browser what width the layout is expected to give the image. See the &lt;a href="https://html.spec.whatwg.org/multipage/images.html#responsive-images" rel="noopener noreferrer"&gt;HTML standard’s responsive image model&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At a viewport width of 390 CSS pixels, the slot is about 358 pixels wide. At 2× device pixel ratio, that’s roughly 716 physical pixels, so the 800-pixel file is a sensible candidate. The browser makes the final choice; don’t treat any one filename as guaranteed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check what the browser actually downloads
&lt;/h2&gt;

&lt;p&gt;From the demo directory, start a local server and open &lt;code&gt;http://localhost:8000&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 -m http.server 8000 --bind 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In Chrome DevTools, set the viewport to 390 CSS pixels and the device pixel ratio to 2. Open &lt;strong&gt;Network&lt;/strong&gt;, filter to &lt;strong&gt;Img&lt;/strong&gt;, enable &lt;strong&gt;Disable cache&lt;/strong&gt;, and reload. Record the requested filename and its transfer size. The &lt;a href="https://developer.chrome.com/docs/devtools/network/reference/" rel="noopener noreferrer"&gt;Network reference&lt;/a&gt; explains how to read these values.&lt;/li&gt;
&lt;li&gt;To see the effect of a wrong hint, use a 1100-pixel viewport at 1×. First reload with the correct &lt;code&gt;sizes&lt;/code&gt;: the browser is told the slot is 600 pixels wide. Then change &lt;code&gt;sizes&lt;/code&gt; to &lt;code&gt;100vw&lt;/code&gt; and reload: the hint now says 1100 pixels, even though the layout hasn't changed. Compare which file is requested in each run. The two hints favor different candidates, but the browser makes the final choice.&lt;/li&gt;
&lt;li&gt;Run the same check on your deployed page. If you use a CDN, check the response type as well: the file delivered to the browser may use a different encoding than the one in your build folder.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the request is hard to identify in the Network panel, this shows which URL the browser selected and how wide it rendered the image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.hero img'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentSrc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;cssWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;dpr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;devicePixelRatio&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;currentSrc&lt;/code&gt; tells you which URL was selected; use the Network panel to see whether and how many bytes were transferred.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix the expensive part first
&lt;/h2&gt;

&lt;p&gt;If a phone is getting an unnecessarily large candidate, fix the layout hint before lowering quality. If it’s getting the right candidate but the file is still too large, change the encoding and compare the result at its actual display size. A smaller export is useful only if it’s the one your readers receive.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>html</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A Reproducible PDF Compress Workflow for Email, Portals, and Web Delivery</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Mon, 23 Nov 2026 08:24:04 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/a-reproducible-pdf-compress-workflow-for-email-portals-and-web-delivery-lc4</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/a-reproducible-pdf-compress-workflow-for-email-portals-and-web-delivery-lc4</guid>
      <description>&lt;p&gt;A PDF can open perfectly on a developer’s laptop and still be a poor delivery asset.&lt;/p&gt;

&lt;p&gt;It may exceed an email attachment limit, fail an application portal, take too long to download on mobile, or contain far more image data than the reader needs.&lt;/p&gt;

&lt;p&gt;A useful &lt;strong&gt;PDF compress&lt;/strong&gt; workflow does not begin with the strongest preset. It begins with a delivery constraint: where the document is going, how large it may be, and which parts must survive processing.&lt;/p&gt;

&lt;p&gt;This guide builds a repeatable workflow around source inspection, structural optimization, image downsampling, and output validation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep the original PDF unchanged.&lt;/li&gt;
&lt;li&gt;Define a measurable delivery target before compressing.&lt;/li&gt;
&lt;li&gt;Inspect images, fonts, pages, and embedded objects.&lt;/li&gt;
&lt;li&gt;Try a structural optimization pass before reducing image quality.&lt;/li&gt;
&lt;li&gt;Generate separate candidates instead of repeatedly compressing one output.&lt;/li&gt;
&lt;li&gt;Validate page count, text, links, forms, signatures, and visual clarity.&lt;/li&gt;
&lt;li&gt;Leave headroom below hard upload limits.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Start with the delivery constraint
&lt;/h2&gt;

&lt;p&gt;“Make the PDF smaller” is not a testable requirement.&lt;/p&gt;

&lt;p&gt;“Keep the document below 9 MB while preserving readable charts, searchable text, and working links” is.&lt;/p&gt;

&lt;p&gt;Different delivery cases need different trade-offs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Delivery case&lt;/th&gt;
&lt;th&gt;Primary constraint&lt;/th&gt;
&lt;th&gt;What to verify&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Email attachment&lt;/td&gt;
&lt;td&gt;Hard size limit&lt;/td&gt;
&lt;td&gt;Final size with safety margin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application portal&lt;/td&gt;
&lt;td&gt;Size and format rules&lt;/td&gt;
&lt;td&gt;Page order, signatures, and required fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Documentation download&lt;/td&gt;
&lt;td&gt;Transfer size&lt;/td&gt;
&lt;td&gt;Mobile loading and link behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scanned archive&lt;/td&gt;
&lt;td&gt;Legibility&lt;/td&gt;
&lt;td&gt;Small text, stamps, and handwritten notes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Print handout&lt;/td&gt;
&lt;td&gt;Output quality&lt;/td&gt;
&lt;td&gt;Images, thin lines, and color&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long-term archive&lt;/td&gt;
&lt;td&gt;Source fidelity&lt;/td&gt;
&lt;td&gt;Preserve the untouched original&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Write down the target before selecting a &lt;strong&gt;PDF compress&lt;/strong&gt; setting. Otherwise, the process becomes a race toward the smallest number rather than a controlled delivery task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspect the source before changing it
&lt;/h2&gt;

&lt;p&gt;A PDF is a container. It may include text streams, fonts, JPEG images, lossless image data, vector graphics, annotations, forms, attachments, and metadata.&lt;/p&gt;

&lt;p&gt;Page count alone does not explain file size. A 20-page scanned document can be much larger than a 200-page text report because every scanned page may be stored as a high-resolution image.&lt;/p&gt;

&lt;p&gt;Poppler provides several useful inspection commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pdfinfo input.pdf
pdfimages -list input.pdf
pdffonts input.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pdfinfo&lt;/code&gt; reports page count, page dimensions, encryption status, metadata, and total file size.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pdfimages -list&lt;/code&gt; helps answer questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How many raster images are embedded?&lt;/li&gt;
&lt;li&gt;Are scanned pages stored at an unnecessarily high resolution?&lt;/li&gt;
&lt;li&gt;Are images using JPEG, JPEG 2000, or lossless streams?&lt;/li&gt;
&lt;li&gt;Does the document contain large color images that will only be viewed on a screen?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;pdffonts&lt;/code&gt; shows which fonts are embedded and whether they are stored as subsets.&lt;/p&gt;

&lt;p&gt;Also check the file’s internal consistency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qpdf --check input.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not begin a compression experiment with the only copy of an important document. Keep the source unchanged and write every candidate to a new file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Estimate where the bytes come from
&lt;/h2&gt;

&lt;p&gt;A useful first classification is:&lt;/p&gt;

&lt;h3&gt;
  
  
  Text-heavy PDF
&lt;/h3&gt;

&lt;p&gt;These files contain searchable text, vector graphics, and relatively few images. They are often already compact.&lt;/p&gt;

&lt;p&gt;Structural cleanup may reduce their size, but aggressive image settings will not help much because images are not the main source of data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image-heavy PDF
&lt;/h3&gt;

&lt;p&gt;Brochures, exported presentations, and illustrated reports often contain large photographs or screenshots.&lt;/p&gt;

&lt;p&gt;These files usually have more room for reduction, but image quality becomes the main constraint.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scanned PDF
&lt;/h3&gt;

&lt;p&gt;A scanned PDF may contain one full-page image per page. Text that appears selectable in some viewers may come from an OCR layer placed over those images.&lt;/p&gt;

&lt;p&gt;Downsampling can save substantial space, but it may also make small print, stamps, signatures, or handwritten notes difficult to read.&lt;/p&gt;

&lt;h3&gt;
  
  
  Feature-rich PDF
&lt;/h3&gt;

&lt;p&gt;Forms, annotations, layers, attachments, JavaScript, certificates, and digital signatures require extra care.&lt;/p&gt;

&lt;p&gt;A PDF rewrite can preserve the visible pages while changing or removing behavior that matters to the workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try a structural pass first
&lt;/h2&gt;

&lt;p&gt;Before reducing image resolution, try rewriting the PDF structure.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;qpdf&lt;/code&gt; can generate object streams and recompress compatible Flate streams:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qpdf \
  --object-streams=generate \
  --recompress-flate \
  input.pdf \
  output-structural.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a relatively conservative &lt;strong&gt;PDF compress&lt;/strong&gt; pass because it does not deliberately downsample every embedded image.&lt;/p&gt;

&lt;p&gt;Run another integrity check afterward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qpdf --check output-structural.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare the sizes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls -lh input.pdf output-structural.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A text-heavy document may become smaller after structural optimization. A scanned document may barely change because most of its bytes are already stored inside compressed image streams.&lt;/p&gt;

&lt;p&gt;A small reduction is still useful if the output remains functionally identical. Do not add quality loss when structural cleanup already meets the delivery requirement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use image downsampling only when justified
&lt;/h2&gt;

&lt;p&gt;When images dominate the file, Ghostscript can produce a new PDF with recompressed and downsampled assets.&lt;/p&gt;

&lt;p&gt;A practical starting candidate is the &lt;code&gt;/ebook&lt;/code&gt; preset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gs \
  -sDEVICE=pdfwrite \
  -dCompatibilityLevel=1.6 \
  -dPDFSETTINGS=/ebook \
  -dNOPAUSE \
  -dQUIET \
  -dBATCH \
  -sOutputFile=output-ebook.pdf \
  input.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Windows, the command may be named &lt;code&gt;gswin64c&lt;/code&gt; instead of &lt;code&gt;gs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The preset is a starting point, not a promise of quality or final size. Ghostscript versions and source documents can behave differently.&lt;/p&gt;

&lt;p&gt;Generate a candidate, then inspect it. Do not overwrite the source.&lt;/p&gt;

&lt;p&gt;For documents containing screenshots, diagrams, or small text, pay particular attention to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;labels inside charts;&lt;/li&gt;
&lt;li&gt;thin table borders;&lt;/li&gt;
&lt;li&gt;syntax-highlighted code;&lt;/li&gt;
&lt;li&gt;QR codes and barcodes;&lt;/li&gt;
&lt;li&gt;stamps and signatures;&lt;/li&gt;
&lt;li&gt;light gray text;&lt;/li&gt;
&lt;li&gt;gradients and transparent elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A photo-heavy brochure may tolerate more image reduction than a scanned legal document.&lt;/p&gt;

&lt;h2&gt;
  
  
  Never compress the previous candidate again
&lt;/h2&gt;

&lt;p&gt;Lossy processing is cumulative.&lt;/p&gt;

&lt;p&gt;This sequence is risky:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;original.pdf
  -&amp;gt; compressed-v1.pdf
  -&amp;gt; compressed-v2.pdf
  -&amp;gt; compressed-v3.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each version inherits the damage introduced by the previous pass.&lt;/p&gt;

&lt;p&gt;Instead, create every candidate from the original:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;original.pdf -&amp;gt; structural.pdf
original.pdf -&amp;gt; ebook.pdf
original.pdf -&amp;gt; stronger-test.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the comparison meaningful and prevents avoidable generational loss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a small candidate matrix
&lt;/h2&gt;

&lt;p&gt;A repeatable workflow records inputs, settings, and results.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Candidate&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;th&gt;Intended use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;original.pdf&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Original&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;24.8 MB&lt;/td&gt;
&lt;td&gt;Archive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;structural.pdf&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Original&lt;/td&gt;
&lt;td&gt;qpdf rewrite&lt;/td&gt;
&lt;td&gt;22.6 MB&lt;/td&gt;
&lt;td&gt;High-fidelity delivery&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ebook.pdf&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Original&lt;/td&gt;
&lt;td&gt;Ghostscript &lt;code&gt;/ebook&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;7.9 MB&lt;/td&gt;
&lt;td&gt;Email attachment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;stronger-test.pdf&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Original&lt;/td&gt;
&lt;td&gt;More aggressive image settings&lt;/td&gt;
&lt;td&gt;3.4 MB&lt;/td&gt;
&lt;td&gt;Portal upload test&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The numbers above are examples, not expected compression ratios.&lt;/p&gt;

&lt;p&gt;A good &lt;strong&gt;PDF compress&lt;/strong&gt; result is the smallest candidate that still satisfies the actual delivery requirement. If the email limit is 10 MB and the 7.9 MB candidate looks correct, the 3.4 MB version may provide no practical benefit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validate with a small Python script
&lt;/h2&gt;

&lt;p&gt;File size alone is not enough. At minimum, confirm that the page count remains stable and that text extraction still produces plausible output.&lt;/p&gt;

&lt;p&gt;Install &lt;code&gt;pypdf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -m pip install pypdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;validate_pdf.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pypdf&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;PdfReader&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"Usage: python validate_pdf.py original.pdf compressed.pdf"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;source_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;output_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PdfReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;source_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PdfReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;source_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;source_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;st_size&lt;/span&gt;
&lt;span class="n"&gt;output_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;st_size&lt;/span&gt;
&lt;span class="n"&gt;saved_percent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;output_size&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;source_size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;extracted_chars&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extract_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
        &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;

&lt;span class="n"&gt;source_chars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extracted_chars&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;output_chars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extracted_chars&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Source size: {source_size / 1024 / 1024:.2f} MB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Output size: {output_size / 1024 / 1024:.2f} MB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Reduction: {saved_percent:.1f}%"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Source pages: {len(source.pages)}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Output pages: {len(output.pages)}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Source extracted characters: {source_chars}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Output extracted characters: {output_chars}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"FAIL: page count changed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;source_chars&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;output_chars&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;source_chars&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"WARNING: extracted text changed significantly"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Automated checks completed; visual review is still required."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python validate_pdf.py input.pdf output-ebook.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Text extraction is not a complete accessibility or content test. Different PDF generators organize text differently, and some scanned documents contain no OCR layer.&lt;/p&gt;

&lt;p&gt;The script is a signal, not proof.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validate the real document behavior
&lt;/h2&gt;

&lt;p&gt;Open the output in more than one PDF viewer when compatibility matters.&lt;/p&gt;

&lt;p&gt;Check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;page count and page order;&lt;/li&gt;
&lt;li&gt;searchable and selectable text;&lt;/li&gt;
&lt;li&gt;bookmarks and table of contents;&lt;/li&gt;
&lt;li&gt;internal and external links;&lt;/li&gt;
&lt;li&gt;form fields and calculated values;&lt;/li&gt;
&lt;li&gt;annotations and comments;&lt;/li&gt;
&lt;li&gt;embedded attachments;&lt;/li&gt;
&lt;li&gt;accessibility tags;&lt;/li&gt;
&lt;li&gt;layers and optional content;&lt;/li&gt;
&lt;li&gt;printing and print preview;&lt;/li&gt;
&lt;li&gt;QR codes, barcodes, stamps, and signatures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Digitally signed PDFs deserve special attention. Rewriting the file can invalidate an existing signature even when the visible pages appear unchanged.&lt;/p&gt;

&lt;p&gt;If the signature must remain valid, do not process the signed document without understanding the signing workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Leave headroom below hard limits
&lt;/h2&gt;

&lt;p&gt;A portal that accepts files up to 10 MB should not receive a candidate that is exactly 10.00 MB.&lt;/p&gt;

&lt;p&gt;Platforms may calculate megabytes differently, add transport overhead, or reject a file after additional processing.&lt;/p&gt;

&lt;p&gt;Aim below the boundary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Portal limit: 10 MB
Practical target: 9 MB or less
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike video encoding, PDF size does not map cleanly to one bitrate formula. A PDF may contain several unrelated data types, each responding differently to optimization.&lt;/p&gt;

&lt;p&gt;That makes candidate generation and validation more reliable than pretending one setting can produce an exact byte count for every document.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where a browser tool fits
&lt;/h2&gt;

&lt;p&gt;A local workflow is preferable when compression must be automated, audited, or applied to confidential documents.&lt;/p&gt;

&lt;p&gt;A browser workflow can still be useful for an occasional, non-sensitive file when no local PDF toolchain is available.&lt;/p&gt;

&lt;p&gt;For example, the &lt;a href="https://videocompress.ai/pdf-compressor" rel="noopener noreferrer"&gt;VideoCompress PDF compress tool&lt;/a&gt; currently provides a browser-based workflow with light, balanced, and strong compression levels. Its page also lists batch processing, PDF files up to 1 GB, and output without a watermark.&lt;/p&gt;

&lt;p&gt;The site states that uploaded documents are automatically deleted within 24 hours. That does not replace an organization’s privacy, compliance, or data-residency requirements.&lt;/p&gt;

&lt;p&gt;Use a non-sensitive sample, preserve the original, and apply the same validation checklist to the downloaded result.&lt;/p&gt;

&lt;p&gt;The tool is an implementation option. The delivery constraint and verification process remain the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common PDF compress mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Starting with the strongest preset
&lt;/h3&gt;

&lt;p&gt;The largest reduction percentage is not necessarily the best result. Start conservatively and stop when the file meets the real requirement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Judging only the first page
&lt;/h3&gt;

&lt;p&gt;A cover page may look perfect while a later scan, chart, or signature has become unreadable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recompressing an earlier output
&lt;/h3&gt;

&lt;p&gt;Return to the original for every candidate. Do not build one lossy result from another.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignoring forms and links
&lt;/h3&gt;

&lt;p&gt;A PDF can look correct while interactive behavior has changed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treating every PDF the same
&lt;/h3&gt;

&lt;p&gt;Text reports, scans, brochures, slide exports, and signed forms have different risk profiles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Targeting the exact upload ceiling
&lt;/h3&gt;

&lt;p&gt;Leave a safety margin rather than relying on a boundary value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting the original
&lt;/h3&gt;

&lt;p&gt;A delivery copy is not an archival source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-delivery checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] The target platform and maximum file size are documented.&lt;/li&gt;
&lt;li&gt;[ ] The untouched original is stored separately.&lt;/li&gt;
&lt;li&gt;[ ] Page count, encryption, images, and fonts were inspected.&lt;/li&gt;
&lt;li&gt;[ ] Structural optimization was tested before image degradation.&lt;/li&gt;
&lt;li&gt;[ ] Every candidate was generated from the original.&lt;/li&gt;
&lt;li&gt;[ ] The output has headroom below the platform limit.&lt;/li&gt;
&lt;li&gt;[ ] Small text, charts, images, stamps, and QR codes were reviewed.&lt;/li&gt;
&lt;li&gt;[ ] Links, bookmarks, forms, and attachments were tested.&lt;/li&gt;
&lt;li&gt;[ ] Signature requirements were checked.&lt;/li&gt;
&lt;li&gt;[ ] The file was opened in the real delivery environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;A reliable &lt;strong&gt;PDF compress&lt;/strong&gt; workflow is a constraint-solving process, not a contest to create the smallest file.&lt;/p&gt;

&lt;p&gt;Inspect the source. Define the destination. Try the least destructive change first. Generate each candidate from the original. Validate structure and visual quality. Then stop when the document is small enough to travel without losing the information that made it useful.&lt;/p&gt;

&lt;p&gt;Once those decisions are written down, PDF delivery becomes repeatable instead of guesswork.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>pdfcompress</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>A Reproducible PDF Compress Workflow for Email, Portals, and Web Delivery</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Mon, 23 Nov 2026 08:21:29 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/a-reproducible-pdf-compress-workflow-for-email-portals-and-web-delivery-2jgc</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/a-reproducible-pdf-compress-workflow-for-email-portals-and-web-delivery-2jgc</guid>
      <description></description>
      <category>pdf</category>
      <category>webdev</category>
      <category>performance</category>
      <category>pdfcompress</category>
    </item>
    <item>
      <title>A Reproducible Video Compress Workflow for Web Delivery</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Wed, 11 Nov 2026 08:17:11 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/a-reproducible-video-compress-workflow-for-web-delivery-2bc6</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/a-reproducible-video-compress-workflow-for-web-delivery-2bc6</guid>
      <description>&lt;p&gt;A video can look perfectly reasonable on a laptop and still be a poor delivery asset. The file may exceed an upload limit, take too long to start on mobile, or consume far more bandwidth than the page around it.&lt;/p&gt;

&lt;p&gt;A useful &lt;strong&gt;video compress&lt;/strong&gt; workflow does not begin with the strongest preset. It begins with a delivery constraint: where the file will play, how large it may be, and which details must survive encoding.&lt;/p&gt;

&lt;p&gt;This guide builds a repeatable workflow around FFmpeg. It covers source inspection, resolution decisions, constant-quality encoding, target-size encoding, and output validation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inspect the source before changing it.&lt;/li&gt;
&lt;li&gt;Remove unused duration before reducing quality.&lt;/li&gt;
&lt;li&gt;Use CRF when visual quality matters more than an exact file size.&lt;/li&gt;
&lt;li&gt;Use a bitrate budget and two-pass encoding when a hard upload limit matters.&lt;/li&gt;
&lt;li&gt;Test the result in the real playback environment.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Start with the delivery constraint
&lt;/h2&gt;

&lt;p&gt;The same source needs different treatment depending on where it is going. A product demo embedded in documentation has different requirements from a video attached to a support ticket.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Delivery case&lt;/th&gt;
&lt;th&gt;Primary constraint&lt;/th&gt;
&lt;th&gt;What to verify&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Web page preview&lt;/td&gt;
&lt;td&gt;Startup time and transfer size&lt;/td&gt;
&lt;td&gt;Playback on a slower network profile&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support or email attachment&lt;/td&gt;
&lt;td&gt;Hard file-size limit&lt;/td&gt;
&lt;td&gt;Final size with a safety margin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UI or code walkthrough&lt;/td&gt;
&lt;td&gt;Text readability&lt;/td&gt;
&lt;td&gt;Small labels, cursors, and terminal output&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Social upload&lt;/td&gt;
&lt;td&gt;Platform compatibility&lt;/td&gt;
&lt;td&gt;Aspect ratio, audio sync, and platform re-encoding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long-term archive&lt;/td&gt;
&lt;td&gt;Source fidelity&lt;/td&gt;
&lt;td&gt;Keep the original instead of optimizing only for delivery&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Write down the constraint before choosing an encoder setting. “Make it smaller” is not testable. “Keep the file below 95 MB while preserving readable 1080p UI text” is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspect the source with &lt;code&gt;ffprobe&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Do not guess what is inside the file. Read its duration, dimensions, frame rate, codecs, and bitrate first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffprobe -v error \
  -show_entries &lt;span class="nv"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;duration,size,bit_rate \
  -show_entries &lt;span class="nv"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;index,codec_type,codec_name,width,height,r_frame_rate,bit_rate \
  -of json \
  input.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output answers several useful questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is the source 4K even though it will render in a 900-pixel content column?&lt;/li&gt;
&lt;li&gt;Is a screen recording stored at 60 fps when 30 fps is sufficient for the motion it contains?&lt;/li&gt;
&lt;li&gt;Is an unexpectedly large audio track consuming part of the budget?&lt;/li&gt;
&lt;li&gt;Has the file already been heavily compressed?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Re-encoding an already damaged file cannot restore missing detail. Keep the original and generate each delivery version from that source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Estimate where the bytes come from
&lt;/h2&gt;

&lt;p&gt;For a quick estimate, file size is mostly a function of total bitrate and duration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;file size (MB) ≈ total bitrate (Mbps) × duration (seconds) ÷ 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A ten-minute file with a total bitrate of 12 Mbps will be roughly 900 MB before container overhead is considered. That explains why resolution alone is not a reliable predictor of size. Two 1080p files with different bitrates can have very different weights.&lt;/p&gt;

&lt;p&gt;Duration is the least destructive variable to reduce. Trim dead air, duplicate takes, loading screens, and long static endings before touching image quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use CRF when quality is the main constraint
&lt;/h2&gt;

&lt;p&gt;For most web previews and documentation videos, an exact byte count is less important than stable visual quality. The Constant Rate Factor mode in &lt;code&gt;libx264&lt;/code&gt; is a practical starting point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -i input.mp4 \
  -c:v libx264 \
  -preset slow \
  -crf 23 \
  -c:a aac \
  -b:a 128k \
  -movflags +faststart \
  output.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-crf 23&lt;/code&gt; controls the quality target. Lower values retain more detail and usually produce larger files. A practical test range is 18–28.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-preset slow&lt;/code&gt; gives the encoder more time to find efficient representations. Presets change encoding effort, not the requested CRF quality level.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-b:a 128k&lt;/code&gt; sets the audio bitrate. Speech-heavy material may not need the same audio budget as music.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-movflags +faststart&lt;/code&gt; moves MP4 metadata toward the beginning of the file, which helps progressive web playback start sooner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run a short representative segment first. A screen recording with small text may need a lower CRF value than a talking-head clip with a simple background.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -ss 00:02:00 -t 30 -i input.mp4 \
  -c:v libx264 -preset slow -crf 23 \
  -c:a aac -b:a 128k \
  sample.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command starts two minutes into the source and encodes a 30-second sample. Choose a section containing motion, text, gradients, and the details that matter to the viewer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scale only when the playback size justifies it
&lt;/h2&gt;

&lt;p&gt;Keeping 4K pixels for a small documentation embed wastes bandwidth. On the other hand, reducing a UI walkthrough too aggressively can make labels unreadable.&lt;/p&gt;

&lt;p&gt;To create a 1080p version while preserving the aspect ratio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -i input.mp4 \
  -vf &lt;span class="s2"&gt;"scale=-2:1080"&lt;/span&gt; \
  -c:v libx264 -preset slow -crf 23 \
  -c:a aac -b:a 128k \
  -movflags +faststart \
  output-1080p.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-2&lt;/code&gt; lets FFmpeg calculate a compatible width from the original aspect ratio. Judge the result at the size users will actually see. Zooming to 400% can reveal artifacts, but it does not tell you whether the delivered experience is acceptable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a bitrate budget for a hard size limit
&lt;/h2&gt;

&lt;p&gt;CRF does not promise a specific output size. When an upload form rejects anything above a fixed limit, calculate a bitrate budget instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;target total bitrate (kbps)
  ≈ target size (MB) × 8192 × 0.97 ÷ duration (seconds)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;0.97&lt;/code&gt; factor leaves a small allowance for container overhead. Subtract the planned audio bitrate to estimate the video bitrate.&lt;/p&gt;

&lt;p&gt;This small Node.js script makes the calculation repeatable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// bitrate-budget.mjs&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;targetMB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;durationSeconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;audioKbps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"128"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;targetMB&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;durationSeconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Usage: node bitrate-budget.mjs &amp;lt;targetMB&amp;gt; &amp;lt;durationSeconds&amp;gt; [audioKbps]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;totalKbps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;targetMB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.97&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;durationSeconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;videoKbps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalKbps&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audioKbps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;videoKbps&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"The target size is too small for the selected audio bitrate."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;targetMB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;targetMB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;durationSeconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;durationSeconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;audioKbps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audioKbps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;videoKbps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a 600-second video targeting 95 MB with 128 kbps audio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node bitrate-budget.mjs 95 600 128
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The calculation produces a video budget of about &lt;code&gt;1130 kbps&lt;/code&gt;. Use that value with two-pass encoding when final size is more important than encoding speed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Pass 1: analyze the video stream&lt;/span&gt;
ffmpeg -y -i input.mp4 \
  -c:v libx264 -b:v 1130k -pass 1 \
  -an -f mp4 /dev/null

&lt;span class="c"&gt;# Pass 2: write the final video and audio&lt;/span&gt;
ffmpeg -i input.mp4 \
  -c:v libx264 -b:v 1130k -pass 2 \
  -c:a aac -b:a 128k \
  -movflags +faststart \
  output-95mb.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Windows, replace &lt;code&gt;/dev/null&lt;/code&gt; with &lt;code&gt;NUL&lt;/code&gt;. The result can still vary slightly, so leave headroom instead of targeting the platform limit exactly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validate more than the final size
&lt;/h2&gt;

&lt;p&gt;An effective &lt;strong&gt;video compress&lt;/strong&gt; pass preserves the information the viewer needs. Check the output in motion, not only through a single thumbnail.&lt;/p&gt;

&lt;p&gt;Inspect these areas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;text, cursor edges, and thin interface lines;&lt;/li&gt;
&lt;li&gt;faces, hair, foliage, and other fine detail;&lt;/li&gt;
&lt;li&gt;gradients, shadows, and dark scenes;&lt;/li&gt;
&lt;li&gt;fast movement and scene changes;&lt;/li&gt;
&lt;li&gt;audio sync at the beginning, middle, and end;&lt;/li&gt;
&lt;li&gt;seeking and startup behavior in the target browser or app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run &lt;code&gt;ffprobe&lt;/code&gt; on the output as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffprobe -v error \
  -show_entries &lt;span class="nv"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;duration,size,bit_rate \
  -show_entries &lt;span class="nv"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;codec_type,codec_name,width,height,r_frame_rate \
  -of json \
  output.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For automated pipelines, record the command, source checksum, output size, duration, and encoder version in a manifest. That turns a one-off optimization into a reproducible build step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where a browser tool fits
&lt;/h2&gt;

&lt;p&gt;FFmpeg is a better foundation when the process must be scripted, reviewed, or repeated across many files. A browser workflow can still be useful for an occasional comparison when no local media environment is available.&lt;/p&gt;

&lt;p&gt;For example, a non-sensitive sample can be processed in &lt;a href="https://videocompress.ai/" rel="noopener noreferrer"&gt;VideoCompress&lt;/a&gt; and compared with the local FFmpeg output. Judge both versions using the same source segment and the same playback conditions. Confidential recordings and unreleased material should remain in an approved environment.&lt;/p&gt;

&lt;p&gt;The tool is only a comparison point here; the workflow and validation criteria remain the same regardless of implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Starting with the strongest preset:&lt;/strong&gt; optimize for the delivery constraint, not the largest reduction percentage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-encoding the previous output:&lt;/strong&gt; return to the original source for every experiment to avoid cumulative damage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Changing several variables at once:&lt;/strong&gt; test CRF, scale, frame rate, and audio settings separately when diagnosing quality loss.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring short motion samples:&lt;/strong&gt; a static frame can hide blocking, smearing, and temporal artifacts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Targeting the exact upload ceiling:&lt;/strong&gt; reserve a few megabytes for bitrate variation and container overhead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keeping only the optimized copy:&lt;/strong&gt; delivery files are not substitutes for an archive-quality original.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pre-publish checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] The delivery size, playback environment, and quality requirement are written down.&lt;/li&gt;
&lt;li&gt;[ ] The source duration, resolution, frame rate, codecs, and bitrate were inspected.&lt;/li&gt;
&lt;li&gt;[ ] Unused duration was removed before lowering quality.&lt;/li&gt;
&lt;li&gt;[ ] A representative short segment was tested first.&lt;/li&gt;
&lt;li&gt;[ ] The output was reviewed at its actual display size.&lt;/li&gt;
&lt;li&gt;[ ] Text, motion, gradients, and audio sync were checked.&lt;/li&gt;
&lt;li&gt;[ ] The final file has headroom below the upload limit.&lt;/li&gt;
&lt;li&gt;[ ] Browser startup and seeking were tested where relevant.&lt;/li&gt;
&lt;li&gt;[ ] The untouched source remains stored separately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;A reliable &lt;strong&gt;video compress&lt;/strong&gt; workflow is a constraint-solving process, not a race toward the smallest file. Inspect the source, choose either a quality target or a size budget, test a representative segment, and validate the result where it will actually play.&lt;/p&gt;

&lt;p&gt;Once those decisions are explicit, they can move into a script or build pipeline. That is the point where video delivery stops being a collection of guesses and becomes a repeatable engineering task.&lt;/p&gt;

</description>
      <category>ffmpeg</category>
      <category>webdev</category>
      <category>performance</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Build an Image Compress Budget Gate Before Heavy Assets Reach Production</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Tue, 20 Oct 2026 08:46:56 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/build-an-image-compress-budget-gate-before-heavy-assets-reach-production-49oc</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/build-an-image-compress-budget-gate-before-heavy-assets-reach-production-49oc</guid>
      <description>&lt;p&gt;The page looked fine in review. The deployment passed. Then someone opened it on a slower mobile connection and found that the new hero image was nearly 5 MB.&lt;/p&gt;

&lt;p&gt;Nothing was technically broken. The file existed, the browser could decode it, and the layout rendered correctly. The problem was that our definition of “ready” did not include an image size limit.&lt;/p&gt;

&lt;p&gt;That is where an image budget helps. Instead of treating image compress work as a final manual cleanup, we can make file size part of the build contract. If an asset exceeds the agreed limit, CI should explain the problem before the change reaches production.&lt;/p&gt;

&lt;p&gt;This tutorial builds a small, dependency-free image size gate with Node.js and runs it in GitHub Actions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Define limits by asset role, not one universal number.&lt;/li&gt;
&lt;li&gt;Check individual files and the total image payload.&lt;/li&gt;
&lt;li&gt;Fail CI with an actionable message.&lt;/li&gt;
&lt;li&gt;Keep compression separate from validation.&lt;/li&gt;
&lt;li&gt;Adjust budgets using real production measurements.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why a valid image can still be a broken artifact
&lt;/h2&gt;

&lt;p&gt;Most build pipelines answer questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does the file exist?&lt;/li&gt;
&lt;li&gt;Does the application compile?&lt;/li&gt;
&lt;li&gt;Do tests pass?&lt;/li&gt;
&lt;li&gt;Can the browser render the asset?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those checks are necessary, but they do not tell us whether a file is appropriate for delivery. A 4,000-pixel photograph may be valid while still being wasteful inside a 900-pixel content column.&lt;/p&gt;

&lt;p&gt;An image compress workflow reduces the file after someone notices the problem. An image budget moves the decision earlier. It turns “this feels too large” into a rule that can be reviewed, versioned, and enforced.&lt;/p&gt;

&lt;p&gt;The goal is not to make every image as small as possible. The goal is to catch accidental weight before it becomes a user-facing regression.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with budgets you can explain
&lt;/h2&gt;

&lt;p&gt;A single limit for every image is tempting, but it ignores how assets are used. A full-width hero, a product thumbnail, and a small icon have different requirements.&lt;/p&gt;

&lt;p&gt;Here is a reasonable starting point for a content site:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Asset group&lt;/th&gt;
&lt;th&gt;Example limit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hero image&lt;/td&gt;
&lt;td&gt;350 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Article image&lt;/td&gt;
&lt;td&gt;220 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Thumbnail&lt;/td&gt;
&lt;td&gt;100 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Icon or badge&lt;/td&gt;
&lt;td&gt;30 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total images on one page&lt;/td&gt;
&lt;td&gt;1 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are not universal standards. A photography portfolio may accept larger files, while a documentation site can be stricter. What matters is that each limit reflects the rendered size, visual importance, and network conditions of the audience.&lt;/p&gt;

&lt;p&gt;Treat the image compress budget as a project constraint rather than a universal score. It should describe what your pages can afford, not force unrelated assets into the same preset.&lt;/p&gt;

&lt;p&gt;Start with current production data. Identify the heaviest pages, inspect their image requests, and choose a first budget that catches obvious mistakes without blocking normal work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a dependency-free size checker
&lt;/h2&gt;

&lt;p&gt;The following script scans an image directory, checks every supported file, and fails when either an individual file or the combined folder size exceeds the budget.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;scripts/check-image-budget.mjs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;readdir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stat&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node:fs/promises&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;extname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;relative&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node:path&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;public/images&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maxFileBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MAX_IMAGE_KB&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maxTotalBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MAX_IMAGE_TOTAL_KB&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;1500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imageExtensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.jpeg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.webp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.avif&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.gif&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;entries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;readdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;withFileTypes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fullPath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isDirectory&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullPath&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;imageExtensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;extname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toKB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt; KB`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;failures&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;totalBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;totalBytes&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;maxFileBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt; is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;toKB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;; limit is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;toKB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;maxFileBytes&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalBytes&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;maxTotalBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;`Total image size is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;toKB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalBytes&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;; limit is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;toKB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;maxTotalBytes&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Image budget exceeded:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;failure&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`- &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Resize, convert, or compress the affected assets, then run the check again.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;`Image budget passed: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; files, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;toKB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalBytes&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt; total.`&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it locally with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MAX_IMAGE_KB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;250 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nv"&gt;MAX_IMAGE_TOTAL_KB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1500 &lt;span class="se"&gt;\&lt;/span&gt;
node scripts/check-image-budget.mjs public/images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This first version intentionally checks bytes, not perceived quality. CI can tell us that a file is too large; a person still needs to decide whether resizing, format conversion, or a gentler image compress setting is the correct fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the gate to GitHub Actions
&lt;/h2&gt;

&lt;p&gt;Run the same command on pull requests so the feedback appears before merge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Image budget&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;public/images/**"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;scripts/check-image-budget.mjs"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.github/workflows/image-budget.yml"&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;check-images&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;22&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check image budget&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;MAX_IMAGE_KB&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250&lt;/span&gt;
          &lt;span class="na"&gt;MAX_IMAGE_TOTAL_KB&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1500&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node scripts/check-image-budget.mjs public/images&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;paths&lt;/code&gt; filter avoids running the job when a pull request changes unrelated code. The limits remain visible in the workflow, which makes a budget change an explicit code review decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make failures actionable
&lt;/h2&gt;

&lt;p&gt;A gate is useful only when developers know how to recover. “Build failed” is not enough. The check should name the file, show its current size, state the allowed size, and suggest the next step.&lt;/p&gt;

&lt;p&gt;A useful image compress gate therefore reports a repair path, not only a red status icon.&lt;/p&gt;

&lt;p&gt;When a file fails, use this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check dimensions.&lt;/strong&gt; If the source is much wider than its largest rendered size, resize it first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the format.&lt;/strong&gt; A photograph exported as PNG may be better suited to JPEG, WebP, or AVIF.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply image compression.&lt;/strong&gt; Compare at least two quality levels at the actual display size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retest the page.&lt;/strong&gt; Confirm that text, gradients, transparency, and important details still look correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the budget check again.&lt;/strong&gt; Validation should use the final file that will be deployed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For occasional assets, a browser tool such as &lt;a href="https://imagecompress.ai/" rel="noopener noreferrer"&gt;ImageCompress&lt;/a&gt; can help compare a smaller output without opening a full image editor. For private or unreleased material, review the service’s file-handling policy or keep processing inside an approved local workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do not let CI silently rewrite assets
&lt;/h2&gt;

&lt;p&gt;It may seem convenient to have CI automatically run an image compress command and commit the result. In practice, that hides an important visual decision.&lt;/p&gt;

&lt;p&gt;Different assets fail in different ways. Photographs can develop blocking around edges, screenshots can lose text clarity, and transparent graphics can gain halos. A fully automatic rewrite may pass the byte limit while damaging the image’s purpose.&lt;/p&gt;

&lt;p&gt;A safer separation is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local tooling or a controlled build step creates optimized candidates;&lt;/li&gt;
&lt;li&gt;a developer reviews the visual result;&lt;/li&gt;
&lt;li&gt;CI validates the committed output against the budget.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Automation should prevent regressions, not remove the quality review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Improve the rule as the project grows
&lt;/h2&gt;

&lt;p&gt;The basic script is intentionally small. A production system can extend it in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use different limits for &lt;code&gt;hero/&lt;/code&gt;, &lt;code&gt;content/&lt;/code&gt;, and &lt;code&gt;thumbnails/&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;inspect pixel dimensions with an image metadata library;&lt;/li&gt;
&lt;li&gt;compare only files changed in the pull request;&lt;/li&gt;
&lt;li&gt;publish a size report as a pull request comment;&lt;/li&gt;
&lt;li&gt;track page-level transfer size with Lighthouse or a browser test;&lt;/li&gt;
&lt;li&gt;allow documented exceptions for assets that genuinely need more detail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Be careful with permanent exceptions. If every failure becomes a larger limit, the budget stops protecting anything. An exception should explain why the heavier asset is necessary and which page owns the cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this check does not solve
&lt;/h2&gt;

&lt;p&gt;A small file can still load late. The browser may discover it only after JavaScript runs, the server may omit effective caching, or the page may lazy-load its main visual by mistake.&lt;/p&gt;

&lt;p&gt;The budget covers transfer weight. It does not replace responsive &lt;code&gt;srcset&lt;/code&gt; candidates, correct &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;, caching, request prioritization, or performance measurement in real browsers.&lt;/p&gt;

&lt;p&gt;Think of it as one reliable boundary in a larger delivery system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-merge checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] The source dimensions match the asset’s intended display size.&lt;/li&gt;
&lt;li&gt;[ ] The format fits the visual content.&lt;/li&gt;
&lt;li&gt;[ ] The &lt;strong&gt;image compress&lt;/strong&gt; result was reviewed at normal zoom.&lt;/li&gt;
&lt;li&gt;[ ] The file passes its individual size budget.&lt;/li&gt;
&lt;li&gt;[ ] The page stays within its total image budget.&lt;/li&gt;
&lt;li&gt;[ ] Responsive variants exist where they provide a real benefit.&lt;/li&gt;
&lt;li&gt;[ ] The pull request explains any approved exception.&lt;/li&gt;
&lt;li&gt;[ ] The deployed request size is verified in browser tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;The most expensive image regressions are often ordinary mistakes: an original camera export, a screenshot saved in the wrong format, or a replacement asset with much larger dimensions than the file before it.&lt;/p&gt;

&lt;p&gt;A small CI gate catches those mistakes while they are still easy to fix. It also turns image compress decisions into shared engineering rules instead of relying on someone to remember a checklist before every release.&lt;/p&gt;

&lt;p&gt;Start with one directory and one understandable limit. Run the check in warning mode if necessary, observe what it catches, and tighten the budget using real page data. Once the rule reflects the project’s needs, make it a required check.&lt;/p&gt;

&lt;p&gt;The build should not only prove that an image can ship. It should also prove that the image belongs in the delivery budget.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Image Compress Workflow: Reduce File Size Without Ruining Quality</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Tue, 20 Oct 2026 03:10:20 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/image-compress-workflow-reduce-file-size-without-ruining-quality-jbf</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/image-compress-workflow-reduce-file-size-without-ruining-quality-jbf</guid>
      <description>&lt;p&gt;Large images are one of the easiest ways to make a fast website feel slow. A single photo exported directly from a camera or design tool can outweigh the HTML, CSS, and JavaScript used to render the entire page.&lt;/p&gt;

&lt;p&gt;An effective image compress workflow is not about pushing every file toward the lowest possible number. It is about removing data the visitor will never see while preserving the detail that makes the image useful.&lt;/p&gt;

&lt;p&gt;This guide walks through a repeatable process you can apply to blogs, product pages, portfolios, and documentation sites.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resize before compressing.&lt;/li&gt;
&lt;li&gt;Match the file format to the image content.&lt;/li&gt;
&lt;li&gt;Judge quality at the actual display size.&lt;/li&gt;
&lt;li&gt;Deliver responsive variants and lazy-load only non-critical images.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why image weight matters
&lt;/h2&gt;

&lt;p&gt;Images often account for a large share of a page's transferred bytes. Reducing that weight can shorten downloads, lower mobile data usage, and make content appear sooner on slower connections.&lt;/p&gt;

&lt;p&gt;However, image compress work is only one part of web performance. A small hero can still appear late if its URL is hidden behind client-side rendering, while an image discovered immediately can still delay the page if it is several megabytes. Measure transfer size, discovery time, and rendering separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Resize before you compress
&lt;/h2&gt;

&lt;p&gt;The most common mistake is placing a 5,000-pixel photo inside a content column that never exceeds 900 pixels. CSS may display it at the correct width, but the browser still downloads the original file.&lt;/p&gt;

&lt;p&gt;A practical image compress process begins with the rendered dimensions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the largest rendered size.&lt;/li&gt;
&lt;li&gt;Resize the source while preserving its aspect ratio.&lt;/li&gt;
&lt;li&gt;Compress the resized version.&lt;/li&gt;
&lt;li&gt;Preview it in the real layout.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If an article image displays at 800 pixels wide, a 1,200- or 1,600-pixel source may be enough. Resizing first usually reaches a reasonable file size without an aggressive quality setting.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Choose a format based on the content
&lt;/h2&gt;

&lt;p&gt;No format is best for every asset. Choose based on whether the image is a photograph, screenshot, logo, or transparent graphic.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Good for&lt;/th&gt;
&lt;th&gt;Watch out for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JPEG&lt;/td&gt;
&lt;td&gt;Photos, gradients, product shots&lt;/td&gt;
&lt;td&gt;No transparency; artifacts appear at low quality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PNG&lt;/td&gt;
&lt;td&gt;Logos, UI screenshots, sharp lines&lt;/td&gt;
&lt;td&gt;Photographs can become unnecessarily large&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;Photos and graphics for modern web delivery&lt;/td&gt;
&lt;td&gt;Keep your build and fallback strategy consistent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AVIF&lt;/td&gt;
&lt;td&gt;High compression efficiency for supported workflows&lt;/td&gt;
&lt;td&gt;Encoding can be slower; verify tool and browser requirements&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Format selection is part of the image compress decision. Converting a photo from PNG to WebP may save more than repeatedly lowering PNG quality, while a text-heavy screenshot may look better as PNG or lossless WebP.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Evaluate quality where users will see it
&lt;/h2&gt;

&lt;p&gt;A quality value of &lt;code&gt;80&lt;/code&gt; does not produce identical results for every image. Hair, foliage, gradients, and small interface text often reveal damage early.&lt;/p&gt;

&lt;p&gt;When reviewing an image compress result, inspect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;faces and product edges;&lt;/li&gt;
&lt;li&gt;text and icons in screenshots;&lt;/li&gt;
&lt;li&gt;smooth gradients and transparent edges;&lt;/li&gt;
&lt;li&gt;QR codes that must remain readable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, view it at the real rendered size. A tiny artifact at 400% may not matter, while blurred text can remain distracting on a phone. File size is a constraint, not the only success metric.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Send responsive image candidates
&lt;/h2&gt;

&lt;p&gt;Even a well-compressed desktop image may be wasteful on a small screen. Use &lt;code&gt;srcset&lt;/code&gt; and &lt;code&gt;sizes&lt;/code&gt; so the browser can choose a suitable candidate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt;
  &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"workspace-960.webp"&lt;/span&gt;
  &lt;span class="na"&gt;srcset=&lt;/span&gt;&lt;span class="s"&gt;"workspace-480.webp 480w,
          workspace-960.webp 960w,
          workspace-1440.webp 1440w"&lt;/span&gt;
  &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"(max-width: 768px) 100vw, 960px"&lt;/span&gt;
  &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"960"&lt;/span&gt;
  &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"640"&lt;/span&gt;
  &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"A desk with a laptop and design sketches"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each candidate needs its own image compress pass. The browser selects among the files you provide; it does not automatically optimize an oversized source.&lt;/p&gt;

&lt;p&gt;Including &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; gives the browser an aspect ratio before the file arrives, reserving space and reducing layout movement.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Use lazy loading selectively
&lt;/h2&gt;

&lt;p&gt;Below-the-fold images are good candidates for &lt;code&gt;loading="lazy"&lt;/code&gt;. Do not apply it to every image by habit. The main hero or likely Largest Contentful Paint image usually needs to be fetched early, and delaying it can make the page feel slower even after image compress optimization.&lt;/p&gt;

&lt;p&gt;Compression changes transfer size. Lazy loading changes request timing. Use each technique for the problem it actually solves.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Build a repeatable optimization routine
&lt;/h2&gt;

&lt;p&gt;For occasional blog images, a manual workflow can be enough:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Save the untouched original.&lt;/li&gt;
&lt;li&gt;Crop unused space and generate the required dimensions.&lt;/li&gt;
&lt;li&gt;Select the output format.&lt;/li&gt;
&lt;li&gt;Apply image compress settings and compare the result.&lt;/li&gt;
&lt;li&gt;Test on desktop, mobile, and a slower network profile.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For a small batch, a browser-based tool can make comparison convenient. For example, &lt;a href="https://imagecompress.ai/" rel="noopener noreferrer"&gt;ImageCompress&lt;/a&gt; can be used when you want to prepare common web images without opening a full editing application.&lt;/p&gt;

&lt;p&gt;Before using any online service, check how files are processed and deleted. Confidential documents, internal designs, and unreleased product images should stay in a trusted environment.&lt;/p&gt;

&lt;p&gt;Once optimization becomes routine, automate maximum dimensions, formats, quality ranges, and responsive variants in the build system or CDN. Verify transferred files in the browser Network panel and compare performance tests under consistent conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compressing the full-resolution original:&lt;/strong&gt; resize to the required dimensions first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimizing only for a percentage:&lt;/strong&gt; a large reduction is meaningless if text becomes unreadable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Applying one preset to every asset:&lt;/strong&gt; photos, logos, and screenshots need different settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring mobile candidates:&lt;/strong&gt; a compressed desktop file can still be too large for a phone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy-loading the hero image:&lt;/strong&gt; prioritize critical visuals and defer only lower content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pre-publish checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] The image dimensions match the largest rendered size.&lt;/li&gt;
&lt;li&gt;[ ] The format fits the image content.&lt;/li&gt;
&lt;li&gt;[ ] The image compress result has been checked at actual display size.&lt;/li&gt;
&lt;li&gt;[ ] Responsive candidates are available where they provide value.&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, and meaningful &lt;code&gt;alt&lt;/code&gt; text are present.&lt;/li&gt;
&lt;li&gt;[ ] Below-the-fold images use lazy loading.&lt;/li&gt;
&lt;li&gt;[ ] The critical hero image is not unnecessarily delayed.&lt;/li&gt;
&lt;li&gt;[ ] The original asset is stored separately.&lt;/li&gt;
&lt;li&gt;[ ] The real network request was verified in browser tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;A good image compress workflow delivers only the pixels and bytes a user needs, at the moment they need them.&lt;/p&gt;

&lt;p&gt;Start with one high-impact image. Resize it, test two suitable formats, compare quality at the rendered size, and measure the actual transfer. Once the result is repeatable, turn the decisions into build rules.&lt;/p&gt;

&lt;p&gt;The result is better performance without sacrificing the visual quality your content depends on.&lt;/p&gt;

</description>
      <category>image</category>
      <category>compressor</category>
      <category>ai</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I Built a Free Online PDF Compressor — No Signup, No Watermark</title>
      <dc:creator>王康</dc:creator>
      <pubDate>Tue, 13 Oct 2026 10:02:33 +0000</pubDate>
      <link>https://dev.to/_cafda18cb1684fc076f294/i-built-a-free-online-pdf-compressor-no-signup-no-watermark-28kh</link>
      <guid>https://dev.to/_cafda18cb1684fc076f294/i-built-a-free-online-pdf-compressor-no-signup-no-watermark-28kh</guid>
      <description>&lt;p&gt;Hi everyone!&lt;/p&gt;

&lt;p&gt;I recently built a small project called &lt;a href="https://pdfcompress.ai/" rel="noopener noreferrer"&gt;PDFCompress&lt;/a&gt; — a free online tool that helps people reduce PDF file sizes without installing software, creating an account, or adding a watermark.&lt;/p&gt;

&lt;p&gt;The goal was simple: make PDF compression fast, flexible, and easy enough for anyone to use.&lt;/p&gt;

&lt;p&gt;💡 The Problem&lt;/p&gt;

&lt;p&gt;Large PDF files are surprisingly inconvenient.&lt;/p&gt;

&lt;p&gt;They can exceed email attachment limits, take too long to upload, consume unnecessary storage space, and become difficult to share on mobile devices or slower networks.&lt;/p&gt;

&lt;p&gt;There are already plenty of online PDF compressors, but many of them come with frustrating restrictions: mandatory registration, hidden fees, watermarks, small upload limits, or very little control over the final result.&lt;/p&gt;

&lt;p&gt;I wanted to create a simpler workflow:&lt;/p&gt;

&lt;p&gt;Upload → choose a compression level → compress → download&lt;/p&gt;

&lt;p&gt;No unnecessary steps and no confusing interface.&lt;/p&gt;

&lt;p&gt;🛠️ What I Built&lt;/p&gt;

&lt;p&gt;PDFCompress works directly in the browser and supports PDF files up to 1 GB. Users can upload and process up to five files at once, which is useful when compressing reports, scanned documents, presentations, application materials, or other large PDFs.&lt;/p&gt;

&lt;p&gt;The tool provides several compression options:&lt;/p&gt;

&lt;p&gt;Low compression: preserves more detail and is suitable for printing, portfolios, and professional documents.&lt;/p&gt;

&lt;p&gt;Medium compression: balances quality and file size for everyday sharing.&lt;/p&gt;

&lt;p&gt;High compression: produces the smallest possible file for email attachments and online uploads.&lt;/p&gt;

&lt;p&gt;Grayscale mode: removes unnecessary color information for additional size reduction.&lt;/p&gt;

&lt;p&gt;Depending on the document and selected mode, PDFCompress can typically reduce its size by approximately 20%–80% while keeping the text, images, and layout clear.&lt;/p&gt;

&lt;p&gt;⚙️ Balancing File Size and Quality&lt;/p&gt;

&lt;p&gt;One of the biggest challenges with PDF compression is that there is no single setting that works perfectly for every document.&lt;/p&gt;

&lt;p&gt;A scanned PDF containing hundreds of images needs a different strategy from a mostly text-based report. Compress too little, and the resulting file is still too large. Compress too aggressively, and images or small text may lose clarity.&lt;/p&gt;

&lt;p&gt;Instead of hiding this tradeoff, PDFCompress gives users a few straightforward compression levels. This keeps the interface simple while still allowing people to decide what matters most for their document: visual quality, smaller file size, or a balance between the two.&lt;/p&gt;

&lt;p&gt;🔒 Privacy Was Part of the Product Design&lt;/p&gt;

&lt;p&gt;PDF files often contain personal, academic, financial, or business information, so privacy could not be treated as an afterthought.&lt;/p&gt;

&lt;p&gt;Files uploaded to PDFCompress are encrypted during transfer and processing. Both the original and compressed files are automatically deleted within 24 hours and are not stored or shared.&lt;/p&gt;

&lt;p&gt;The service also requires no account, which means users can compress a document without providing personal registration details.&lt;/p&gt;

&lt;p&gt;🧪 Lessons Learned&lt;/p&gt;

&lt;p&gt;A few things became especially clear while building the product:&lt;/p&gt;

&lt;p&gt;Users care about the final file size, but they care just as much about whether the document still looks good.&lt;/p&gt;

&lt;p&gt;A single compression preset cannot handle every type of PDF effectively.&lt;/p&gt;

&lt;p&gt;Supporting large files and batch processing makes the tool much more useful in real workflows.&lt;/p&gt;

&lt;p&gt;Privacy information should be visible before users upload a file.&lt;/p&gt;

&lt;p&gt;A focused interface is often better than a feature-heavy one—most people simply want to upload a PDF, make it smaller, and download it.&lt;/p&gt;

&lt;p&gt;🌍 Try It Out&lt;/p&gt;

&lt;p&gt;If you regularly need to email reports, submit documents through online portals, or save storage space, you can try PDFCompress here:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://pdfcompress.ai/" rel="noopener noreferrer"&gt;https://pdfcompress.ai/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is free to use, requires no registration, and adds no watermark to the compressed document.&lt;/p&gt;

&lt;p&gt;I would love to hear your feedback—esp&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>buildinpublic</category>
    </item>
  </channel>
</rss>
