Getting started with Pagelean
This guide walks you through installing Pagelean and safely removing unneeded JavaScript and CSS assets from pages where they are not required.
Why unload scripts conditionally?
Section titled “Why unload scripts conditionally?”Most WordPress plugins register and load their CSS stylesheets and JavaScript files on every single page load across your entire site. For example, a contact form plugin often enqueues its scripts on blog articles and the homepage, even though the form only exists on a single /contact page.
These unnecessary requests:
- Increase total page payload and HTTP requests.
- Block the main browser thread during parsing and execution.
- Negatively impact Core Web Vitals metrics, specifically Largest Contentful Paint (LCP) and Interaction to Next Paint (INP).
Pagelean solves this by hooking into WordPress core’s native enqueue pipeline (wp_dequeue_script and wp_dequeue_style) at priority 100, dropping specified assets on matching pages.
Installation and activation
Section titled “Installation and activation”- Log into your WordPress administrative dashboard.
- Go to Plugins > Add New and search for Pagelean, or upload the plugin files to
wp-content/plugins/pagelean. - Click Activate.
- Upon activation, Pagelean adds a top-level Pagelean menu item in your WordPress admin menu.
The safe 3-step test mode workflow
Section titled “The safe 3-step test mode workflow”Modifying asset loading can inadvertently break frontend interactive features if done carelessly. Pagelean includes a dedicated Test mode switch to make changes safely without affecting live visitors:
- Turn on Test Mode:
- In the WordPress admin, navigate to Pagelean.
- Check the Test mode toggle at the top of the screen and click Save rules.
- While Test Mode is enabled, every admin screen displays a notice: “Pagelean test mode is on.”
- Rules will now apply exclusively to logged-in administrators with the
manage_optionscapability. Normal site visitors and search engine bots continue to receive the standard, untouched page.
- Discover handles and add rules:
- Browse your frontend pages while logged in as an administrator. Pagelean records the assets loaded on each page into its internal discovery registry (up to 500 handles).
- Return to the Pagelean admin screen and add rules for the handles you wish to remove.
- Test the affected frontend pages in your browser: check visual layout, form submissions, and browser console errors.
- Turn off Test Mode:
- Once you confirm that the pages render cleanly and all interactive elements function properly, uncheck Test mode and click Save rules.
- The rules now apply globally to all site visitors.
Adding your first rule
Section titled “Adding your first rule”- In the Pagelean admin screen, click + Add rule.
- Handle: Enter the script or stylesheet handle name (e.g.,
contact-form-7). The field will provide autocomplete suggestions based on handles recorded during your browsing. - Type: Select Script (JS) or Style (CSS).
- Remove when: Select the condition (for example, Except single posts/pages (matching IDs) to unload everywhere except your specific contact page).
- Post/Page IDs: Enter the post ID (e.g.,
42) where the asset should continue to load. - Click Save rules.
Test the page to verify that the handle is no longer requested by the browser.