❌

Normal view

There are new articles available, click to refresh the page.
Today — 2 December 2026Main stream

Manually Subset Fonts to Save Bandwidth

9 May 2025 at 00:00

When I started building Cat Cafe Map, I really wanted to keep things as minimal and fast as possible. No unnecessary frameworks, no giant libraries, just a clean site that loads quickly and feels light.

Most of the pages are statically rendered, and I barely touch JavaScript thanks to Astro Islands. My first version shipped under 10kb of JavaScript per page, which felt great. But there was one thing bugging me: my font file. The woff2 file came in at 33kb, which made it three times bigger than the JS payload. Not the end of the world, but it definitely felt unnecessary.

So I decided to trim it down. I added a little build step to subset the font so it only included the glyphs I actually use across the site. To do that, I hacked together a Bash script that scanned through the dist folder, collected all the characters used, and passed them into fonttools to generate a slimmer font file.

The difference was pretty satisfying. The font went from 33kb down to about 10kb, which is roughly a 70% reduction. It doesn’t make a huge difference, but it’s a small optimization that makes the site snappier and keeps bandwidth usage lower.

A terminal showing the file-size savings from font subsetting

Here’s a simple example of how I did it using Bash, Python, and fonttools:

process-fonts.sh
#!/bin/bash
 
# Check and install dependencies
check_and_install_dependencies() {
    # Check for pip
    if ! command -v pip &> /dev/null; then
        echo "pip is not installed. Please install Python and pip first."
        exit 1
    fi
 
    # Check for fonttools and brotli
    if ! python3 -c "import fontTools" &> /dev/null || ! python3 -c "import brotli" &> /dev/null; then
        echo "Installing required Python packages..."
        pip install fonttools brotli
    fi
}
 
# Directory containing your build files
BUILD_DIR="./dist" # adjust this to your build directory
# Directory containing your fonts
FONTS_DIR="./public/fonts"
# Output directory for subsetted fonts
SUBSET_DIR="./public/fonts"
 
# Create subset directory if it doesn't exist
mkdir -p "$SUBSET_DIR"
 
# Function to extract text content from files
extract_text() {
    # Extract text from HTML, JS, CSS files
    find "$BUILD_DIR" -type f \( -name "*.html" -o -name "*.js" -o -name "*.css" \) -exec cat {} + | \
    # Remove HTML tags
    sed 's/<[^>]*>//g' | \
    # Remove special characters but keep unicode
    tr -cd '[:alnum:][:space:][:punct:]\\u0080-\\uffff' | \
    sort -u > /tmp/text_content.txt
}
 
# Create subsets for each font
create_subset() {
    local font=$1
    local basename=$(basename "$font")
    local output="$SUBSET_DIR/${basename%.*}.subset.${basename##*.}"
 
    echo "Creating subset for $basename..."
 
    pyftsubset "$font" \
        --output-file="$output" \
        --text-file=/tmp/text_content.txt \
        --layout-features='*' \
        --flavor=woff2 \
        --desubroutinize
 
    echo "Created subset font: $output"
 
    # Print size comparison
    original_size=$(stat -f %z "$font")
    subset_size=$(stat -f %z "$output")
    echo "Original size: $(($original_size/1024))KB"
    echo "Subset size: $(($subset_size/1024))KB"
    echo "Reduction: $((100-($subset_size*100/$original_size)))%"
}
 
echo "Checking dependencies..."
check_and_install_dependencies
 
echo "Cleaning up old subset fonts..."
find "$SUBSET_DIR" -type f -name "*subset*" -delete
 
echo "Extracting text content from build..."
extract_text
 
echo "Creating font subsets..."
for font in "$FONTS_DIR"/*.woff2; do
    create_subset "$font"
done
 
echo "Cleanup..."
rm /tmp/text_content.txt
 
echo "Done! Subsetted fonts are in $SUBSET_DIR"
Creating font subsets via fonttools

The Correct Way to Load Google AdSense in Next.js

2 April 2025 at 00:00

Adding Google Adsense to a Next.js site is fairly straightforward and simple. You can install @ctrl/react-adsense, use the component with your credentials, and add the Adsense script to pages/_app.js if you’re using Page Router or app/layout.tsx for App Router.

At first glance, this might seem like all you need, but I found out the hard way that this basic implementation is not enough to get the job done. Read on if you’re interested why, otherwise skip to the solution.

A Next.js implementation of Google AdSense

pages/_app.tsx
import Script from 'next/script'
 
// This part was ok ✅
export default function App({ Component, pageProps }) {
  return (
    <>
      <Script
        strategy="afterInteractive"
        src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXX"
        crossOrigin="anonymous"
      />
      <Component {...pageProps} />
    </>
  )
}
Loading the script in Next with page router
AdBanner.tsx
import React from 'react'
import { Adsense } from '@ctrl/react-adsense'
 
// This part was not ❌
export function AdBanner() {
  return <Adsense client="ca-pub-XXXXXXXXXXXXXXXX" slot="XXXXXXXXXX" />
}
Minimal react-adsense setup

The Problem

After running this setup for about four months on a site averaging around 30,000 pageviews per month, I started noticing something odd. My daily ad revenue seemed unusually low, but I initially chalked it up to typical Adsense RPMs. It’s well-known that Adsense doesn’t pay as well as some other ad networks, but given their low barrier to entry, I accepted it as part of the tradeoff.

What didn’t add up was that my analytics dashboard was showing more than twice the pageviews reported by Google Adsense. It didn’t take long to realize that the root cause was likely related to how Next.js handles routing and rendering.

Next.js is a single-page application (SPA) framework under the hood, even when using traditional routing patterns. This means that when users navigate between pages, the browser doesn’t fully reload the page, it simply swaps out content dynamically. While this is great for performance and user experience, it introduces a subtle problem: scripts like Google AdSense are designed to detect full page loads, not internal client-side navigations. As a result, while users were technically viewing multiple pages per session, AdSense wasn’t registering those views because it only initialized once on mount. Without a proper fix, every client-side page change was effectively invisible to the ad system.

The site I was working on, GigFish, is a directory where users typically spend 5 minutes or more per session, browsing an average of 5 or more pages. Because my AdBanner component was only rendering once on a route like the discover page, I was missing out on several page views per user session.

On subsequent navigations, the ad banner kept displaying the same ad because the component never re-rendered.

The Solution

To fix the issue, I replaced the @ctrl/react-adsense component with my own implementation. It’s almost identical but adds a key based on the router path and a retry mechanism to ensure the ad banner is filled if the initial load fails.

Adsense.tsx
import React from 'react'
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import { cn } from '@/lib/utils'
 
export function Adsense({
  className = '',
  style = { display: 'block' },
  client,
  slot,
  layout = '',
  layoutKey = '',
  format = 'auto',
  responsive = 'false',
  pageLevelAds = false,
  adTest,
  children,
  ...rest
}) {
  const router = useRouter()
 
  useEffect(() => {
    const p = {}
    if (pageLevelAds) {
      p.google_ad_client = client
      p.enable_page_level_ads = true
    }
 
    // Fill the space with an ad
    const doPush = () => {
      if (typeof window !== 'object') return
      window.adsbygoogle = window.adsbygoogle || []
      window.adsbygoogle.push(p)
    }
 
    const pushAds = () => {
      try {
        doPush()
      } catch {
        // 👇 THIS IS A FAILSAFE
        setTimeout(() => {
          try {
            doPush()
          } catch (err) {
            console.error('AdSense push retry failed:', err)
          }
        }, 750)
      }
    }
 
    pushAds()
  }, [router.asPath, client, slot, pageLevelAds])
 
  return (
    <ins
      key={router.asPath} // 👈 THIS IS THE IMPORTANT FIX
      className={cn('adsbygoogle', className)}
      style={style}
      data-ad-client={client}
      data-ad-slot={slot}
      data-ad-layout={layout}
      data-ad-layout-key={layoutKey}
      data-ad-format={format}
      data-full-width-responsive={responsive}
      data-adtest={adTest}
      {...rest}
    >
      {children}
    </ins>
  )
}
Filling new ads when the route changes

The router.asPath key signals to React that the component has changed and needs to be re-rendered. Inside the effect, logic attempts to populate the banner with a new ad. If the first attempt fails, which can happen due to the asynchronous loading of the Adsense script, it retries after 750ms. If, after all this, the ad still has the data-ad-status="unfilled" attribute, it’s likely because the Google Adsense script chose not to serve an ad.

After making this change, my AdBanner component correctly re-rendered whenever the URL’s query parameters changed, and I started seeing different ads when navigating between pages. As a result, the pageview count in my Adsense reports began to align much more closely with the numbers from my analytics dashboard. While it’s still a bit early to be certain, my daily ad revenue now looks likely to double in the coming months. 🥳

How to Add a Noise Effect with CSS

20 March 2025 at 00:00

Scrolling through X (Twitter) the other day, I came across a designer showing some landing page concepts he had made with Figma. They all featured this aesthetically pleasing, grainy effect that softened the sharpness of the images.

The basic concept was that he had prompted his way to creating these clean, high-definition image outputs from Midjourney, applied headings, buttons, and marketing copy, then finished it off with this “noise” effect. The result was an accessible approach to quickly designing landing page ideas that got him a few leads to his business without having to even create the actual site.

Noise Effect Tweet

Unfortunately, for design illiterate devs like me, the process involved a Figma plugin called “Shumi Noise”, but it seemed like an easy CSS solution must exist. If you’re interested in the original twitter thread, you can find it here.

Below is a simple proof of concept for an overlay that applies the effect to an image or any element the class is applied to. Simply adjust the opacity or base frequency to produce the desired level of graininess. baseFrequency controls how tight or loose the noise pattern feels, numOctaves adds extra layers of texture, and the opacity on the SVG rectangle keeps the effect from overpowering the actual design. Coupled with some crisp photography, AI artwork, or other design, the effect can make for some pretty epic landing pages with little effort.

Base image
Base Frequency: 0.75
Opacity: 0.30

For a live page, I prefer keeping the grain as a CSS overlay so it can be adjusted without permanently changing the image. For static assets like the cover image or social preview card, baking in a heavier grain pass is totally reasonable since those surfaces won’t run the interactive CSS.

noise-overlay.css
.noise {
  position: relative;
  overflow: hidden;
}
 
.noise::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.3'/%3E%3C/svg%3E");
  pointer-events: none;
}
Add this class to an element to apply noise

The important bit is that .noise needs to be positioned relative, otherwise the absolutely positioned ::before pseudo-element may try to cover some other ancestor instead of the element you meant to target. The content property is what makes the pseudo-element render, and pointer-events: none keeps the overlay from blocking buttons, links, or other interactive pieces underneath it.

For example, you could apply it to a hero like this:

index.html
<section class="hero noise">
  <h1>Your landing page headline</h1>
  <p>Some crisp copy over a crisp image.</p>
</section>

The effect generally looks best when applied to an entire hero section rather than just an image, and most designers pair it with a gradient effect to taper off the graininess towards the edges of the page. It’s a clean way to soften up the bold colors and visual sharpness you usually get from AI image outputs in tools like Midjourney.

Code is Leverage

30 December 2024 at 00:00

What first drew me to programming was the novelty of creating something out of nothing. The idea that I could write a few lines of code and have it turn into a website as simply as you would stack legos as a kid. It felt like play.

But as I grew into my profession, I realized that the code is not the hard part. The hard part is deciding what to build, how to sell it, and who to market it to. The difficult part is building the business, not the programming.

To stay employed solely as a programmer, taking a salary dictated by office politics, an arbitrary title, or location is to trade your potential for a small slice of certainty. It’s a promise of safety without the possibility of non-linear outcomes — work that ends when you stop working.

The real gift of software is leverage. Code is a modern daemon, quietly compounding your effort without fatigue or complaint. It scales beyond your time and energy. You can build it once, and it can serve millions while you sleep. That’s where the real power of programming lies.

Software turning one person’s effort into leverage

The problem with a traditional job is simple: it doesn’t scale. Your income is limited to the time you have available. Your hours become your ceiling. Without ownership, without equity, you are simply renting out your most limited resource.

Worse still, you could code features at work that generate millions, but the spoils aren’t yours. The incentive is to do just enough to meet expectations, but not to exceed them. Why give your best when the upside belongs to someone else?

The real shift happens when you realize that leverage is no longer reserved for the elite. In the past, you needed capital, connections, or factories. Today, you only need a laptop and an internet connection. Code is permissionless leverage. No one needs to give you authority. You can simply build.

The toughest obstacle isn’t learning to code, it’s having the courage to use it for yourself. Most will choose the familiar path: salaries, titles, healthcare, “unlimited” PTO, and praise from bosses who own the real upside. But the few who step off that path and build for themselves unlock the possibility of asymmetric upside. They stop renting out time and start building equity in something that’s entirely theirs.

If you can code, you already hold the keys. The ability to create, automate, and scale is sitting in your hands. No one is stopping you. The only thing left is to act: to place the bet, to take the risk, to build something of your own.

Bet on yourself.

Before yesterdayMain stream

Claude Code is accidentally exposing secrets all over GitHub

9 November 2026 at 17:24

Claude Code is leaking sensitive information on public GitHub instances thanks to a partial oversight in the way its settings files are handled. That's the finding of AI security researchers at Apiiro, who discovered thousands of secrets, including database passwords, API tokens, and root logins, amid Claude Code settings files embedded in GitHub repositories.

The leak stems from the way Claude Code handles user approval for automated shell commands. When a user chooses the "Yes, and don't ask again" option to approve running a command, that choice gets stored as part of a rule in the local ".claude/settings.local.json" file on the user's computer. That rule is sometimes coded as a pattern, but the command itself is often written to that settings file as is, including any sensitive information that may be embedded within it.

This isn't really a significant security issue if the settings file stays on the user's local machine (assuming that machine doesn't become compromised itself, of course). And Anthropic notes in its Claude Code documentation that this particular settings file gets added to the developer's global .gitignore list, which usually prevents it from being shared publicly.

Read full article

Comments

© Aurich Lawson

Traditional Web Development is Dead…(and Honestly? Good Riddance.)

28 September 2026 at 14:49
AI isn't killing web development—it’s killing the boring parts. The real winners won't be the people who can memorize another framework. They'll be the builders who can spot opportunities, solve business problems, and launch products that once required entire teams. The age of the one-person software company has arrived.

AI Can Build Your UI. Now Figma Can Tell It When It Screwed Up.

18 September 2026 at 16:39
AI can now build a UI in seconds, but that doesn't mean it built the UI you actually designed. A new Applitools integration turns Figma designs into visual baselines, automatically catching the subtle differences AI coding agents leave behind before they make it into production.

Canva Is Quietly Publishing Nearly 1 Million Websites a Month

8 September 2026 at 12:02
Canva isn't just for presentations and social posts anymore. Nearly 1 million websites are now being published through Canva every month—and with 100+ new Visual Suite updates, web designers may want to start paying attention.

Set Up Visual Studio Code and xDebug as the Ultimate Editor for WordPress Development

By: Matt Shaw
26 May 2025 at 14:22

Visual Studio Code is a free, open source code editor that is lightweight like Sublime Text, but offers many of the same features as bigger IDEs like PhpStorm or WebStorm.

In this article, I’ll review some features of VS Code that I love, and show you how to make the most out of it for WordPress dev.

Basic Setup for WordPress Development

Most of the time when coding in WordPress, you’re working on a plugin or a theme. One way to do this might be to open that plugin or theme in your IDE and start coding away. There is a better way though, with the help of VS Code “Workspaces”.

You can think of a Workspace in VS Code as a container for your project – it not only includes your project, but it can include files that your project relies on (your WordPress installation), and any extensions or settings specific to that project.

I like Workspaces because you can create one of them for each project and change any setting or extension in VS Code at the Workspace level. For example, you may not want to use the WordPress Coding Standards on all of your projects, or maybe you work with a team of developers that can’t agree on tabs vs. spaces.

In my case, the vast majority of my time is spent on plugin development. So I’ll have a Projects folder that has all of the plugins I work on, and a Sites folder that contains all of my sites. I’ll then symlink the plugin I’m working on into a fresh WordPress website in the Sites folder.

In Visual Studio Code, I’ll first open the plugin itself, and then I’ll add the WordPress site by selecting File -> Add Folder to Workspace. That sets up a new Workspace where I can edit the plugin and the WordPress installation at the same time.

This is handy for quick edits to the wp-config.php file, and keeping an eye on the debug.log file while I’m developing.

Next, click File -> Save Workspace As to save that Workspace. This creates a *.code-workspace file (JSON-based) that stores path folders and settings. This allows you to open your Workspace again in the future, and also serves as a config file that will come in handy later. If you’re collaborating, you can version-control this file—just ensure paths like /Sites/my-site aren’t machine-specific.

Deeper PHP and WordPress Integration

With that out of the way, let’s take a look at how we can make Visual Studio Code and WordPress play a bit nicer. Out-of-the-box, VS Code doesn’t support WordPress and PHP as well as some other IDEs like PhpStorm (Find out how some of our team uses PhpStorm for WordPress Development). Luckily, that’s easy to change by installing some extensions.

Since WordPress is still mostly PHP, I use the PHP Intelephense extension, which adds PHP auto-completions, symbol navigation support, and a much better way to find references in your workspace.

While that will add auto-completions for PHP core functions and anything that you have defined in your project, it won’t pick up on much from WordPress core. For that, there is the Hooks IntelliSense for WordPress extension. It autocompletes WordPress hooks (actions/filters) and their priority parameters. There’s also PHP Tools for Visual Studio Code, which provides advanced IntelliSense for WordPress core functions, classes, and constants. It even resolves argument orders for functions like get_posts(), so you spend less time checking the Codex.

To enforce WordPress best practices, use the WordPress Coding Standards with the PHP Sniffer extension. This combination highlights issues like missing sanitization or incorrect file naming in real time. Just install phpcs globally and configure the extension to use the WordPress standard in your workspace settings.

These tools make it much easier to work with WordPress plugins and themes, and PHP development in general.

Debugging PHP

Xdebug is an invaluable tool to have for debugging PHP, but it can be tricky to set up. Luckily, VS Code makes it easy to configure Xdebug, and in my case it just works.

You only need to install the PHP Debug extension and reload the editor. You can then go to the “Run” tab and click “create a launch.json file” to create a new PHP debug configuration.

Create launch.json for Xdebug.

You should then see a pop-up towards the top of your editor asking you to select a Workspace folder to create the configuration in:

Select workspace for launch.json

Select “workspace” to insert the new configuration into your *.code-workspace file, and then “PHP” to add a PHP configuration. This will add some debug config to that file, including the new “Listen for XDebug” option. You can edit the name of the configuration or change the XDebug port here. Here’s how to adjust the config based on a common MAMP setup:


{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9003, // Xdebug v3+ uses 9003!
    "pathMappings": {
        // Docker example:
        "/var/www/html": "${workspaceFolder}/wp",
        // Local example (MAMP/XAMPP):
        "/Applications/MAMP/htdocs/mysite": "${workspaceFolder}"
    },
    "log": true // Enable logging for troubleshooting
}

In my case, it also added a “Launch currently open script” config as well. With WordPress, we rarely need to load a PHP file directly, so I just deleted that config.

That’s it! You should be able to start debugging PHP from here. Head over to a PHP file in your WordPress plugin or theme, and click to the left to a line number to add a breakpoint to that line.

Setting a breakpoint in VS Code

When you head back over to the “Run” tab, select “Listen for XDebug” from the dropdown and click the play icon to start listening for requests. For breakpoints to work, append ?XDEBUG_SESSION=VSCODE to your site’s URL, or add a browser extension. When your code hits that breakpoint, the runtime should pause and you can see all variables, the call stack, and more. Who knew debugging WordPress in Visual Studio Code could be so easy?

XDebug Ghosting You? Enable Logs

When your breakpoints mysteriously don’t trigger—even though everything seems right—you can add these lines to your php.ini to enable logs:

[xdebug]  
xdebug.log = /tmp/xdebug.log  # Simple path that’s always writable  
xdebug.log_level = 1  # 1=errors, 3=trace (verbose)  

When to Check the Logs:

  • Breakpoints ignored (even with ?XDEBUG_SESSION=VSCODE).
  • VS Code’s debugger says “Connected” but never pauses.
  • You’re muttering “Why isn’t this working?!” at your screen.

What to Look For:

  • “Could not connect to client”: Firewall blocking port 9003? Try changing the port that xDebug listens on or check your local firewall settings..
  • “File is not mapped”: Fix pathMappings in launch.json (e.g., /var/www/html → ${workspaceFolder}).
  • “Invalid session”: Do you have the Xdebug browser extension enabled or are you forgetting to add ?XDEBUG_SESSION=VSCODE to your URL?

Debugging JavaScript

Debugging PHP is only half the problem – we also need to be able todebug JavaScript. Thankfully, modern VS Code has robust tools for this built right in. VS Code’s JavaScript Debugger is bundled with VS Code by default and supports Chrome, Edge, Node.js, and more. No extensions needed!

Next, you’ll need to edit the *.code-workspace file to add a JS debug config. :

{
    "name": "Listen for JS",
    "type": "chrome",
    "request": "launch",
    "url": "http://yoursite.test",
    "webRoot": "/path/to/your/site/root",
}

The type here refers to VS Code’s built-in JavaScript Debugger, which supports Chromium-based browsers. If you prefer Firefox, you can use Mozilla’s Firefox Debugger extension and update the type to "firefox".

Once that’s been added, you should see the Listen for JS option in the debug drop down:

Listen for JS debug option.

For reference, here’s my entire mdb.code-workspace file so far:

{
"folders": [
    {
    "path": "wp-migrate-db-pro"
    },
    {
    "path": "/Users/mattshaw/Sites/mdb/app/public"
    }
],
"launch": {
    "version": "0.2.0",
    "configurations": [
    {
        "type": "chrome",
        "request": "launch",
        "name": "Listen for JS",
        "url": "http://mdb.test",
        "webRoot": "/Users/mattshaw/Sites/mdb/app/public"
    },
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9003
        "pathMappings": {
          "/var/www/html": "${workspaceFolder}/wp"  
        }       
      }
    ]
  }
}

The pathMappings are essential if you’re using Docker or developing remotely. If you’re working locally, you only need them if your server’s file paths differ from your local workspace.

Gotchas

If you’re using something like Webpack to bundle your JS files together, you may notice that your breakpoints aren’t working. Modern tools generate source maps automatically, but if yours aren’t lining up, you should double-check your webpack.config.js for devtool: 'source-map'. Also, in VS Code’s debug config, ensure webRoot matches your server’s document root.

With that in place, it’s now easy to debug JS from within VS Code, using the same UI that is used for Xdebug:

Debugging JS in VS Code

Other Tips

I’ve come across some other important extensions that have been helpful in day-to-day development. The GitLens extension adds simple git blame annotations to the line that you’re currently working on. And now it even integrates with GitHub for pull request insights!

The PHP DocBlocker extension is super helpful for, well, docblocking. Simply type /** above a function, method, or class and it will autocomplete the docblock based on the function/method parameters.

The Prettier extension is great for cleaning up your CSS, JS, and HTML code on editor save.

VS Code’s built-in Markdown preview (no extension needed!) works great for writing docs or blog posts. And if you’re using modern JavaScript, the native syntax highlighting covers ES6+—no plugin required.

Closing Thoughts

After using it for years, I still love VS Code. It’s like it took my favorite features of PhpStorm and Sublime Text, and combined them to create the perfect IDE. I also really like the way that you can install extensions directly from within VS Code, and view the docs for that extension without leaving the editor.

Have you tried out VS Code? What did you think? Let us know in the comments.

The post Set Up Visual Studio Code and xDebug as the Ultimate Editor for WordPress Development appeared first on Delicious Brains.

❌
❌