Skip to content

Pagelean

Pagelean removes specific scripts and styles from the pages where they are not needed. Most plugins enqueue their CSS and JavaScript on every page, even where the feature never appears, and that weight slows every visit. Pagelean uses the standard WordPress enqueue system (wp_dequeue_script / wp_dequeue_style, and optionally wp_deregister_script / wp_deregister_style), so there is nothing proprietary to learn and no page-builder lock-in. It works on any theme and does not require WooCommerce.

For each rule you add, Pagelean checks the current front-end request and, when the rule’s condition matches, dequeues the handle so it is not printed. Rules run on wp_enqueue_scripts at priority 100 (after themes and plugins have enqueued), and never run in the admin.

A dequeued handle is still printed when another enqueued script lists it as a dependency. To remove it even then, tick Also deregister on the rule. Deregistering also drops every script that depends on the handle, so use it only when you know nothing on that page needs it.

At the top of the Pagelean screen:

  • Enable conditional asset loading - the master switch, on by default. When it is off, no rule runs.
  • Test mode - off by default. When on, rules apply only to logged-in users with the manage_options capability (administrators); every other visitor gets the untouched page. While test mode is on, every admin screen shows a “Pagelean test mode is on.” notice.

A safe workflow: turn test mode on, add rules, browse the site as an administrator, then turn test mode off.

Open the Pagelean menu, click + Add rule and fill in:

  • Handle - the registered name of the script or style to remove (e.g. contact-form-7). The field autocompletes from the handles registered on your site.
  • Type - Script (JS) or Style (CSS).
  • Remove when - the condition that decides where the handle is removed.
  • Post/Page IDs - optional, comma-separated, only used by the two single posts/pages conditions; the field is disabled for every other condition.
  • Post type - only used by “On single entries of a post type”.
  • Also deregister - also deregister the handle (see above). Off for new rules.

Click Save rules. Rows without a handle are dropped on save.

  • Everywhere - every front-end page.
  • On the front page - the site front page.
  • On the blog posts index - the posts index.
  • On single posts/pages (matching IDs) - single posts or pages; limit to specific IDs, or leave IDs empty to match any single.
  • Except single posts/pages (matching IDs) - the inverse.
  • On mobile devices / On desktop devices - by wp_is_mobile().
  • On single entries of a post type - single entries of one public post type, chosen in the Post type column.
  • On the WooCommerce shop page, On WooCommerce product pages, On the WooCommerce cart, On the WooCommerce checkout - listed only while WooCommerce is active.

Open the page in your browser, view source or the Network tab, and look at the id attribute of the <script> / <link> tags - it usually ends in -js or -css (the handle is that value without the suffix).

The settings screen also autocompletes handles. The admin screen itself only knows the handles registered in the admin, so Pagelean records the handles your front-end pages load while you browse them logged in as an administrator, and suggests those first, with their source file. Visit a few pages to fill the list. Up to 500 handles are kept, oldest dropped first.

Pagelean removes only what you configure. If a handle you remove is a dependency of another script, that other script may stop working (with Also deregister) or the handle may still load (without it). Change one rule at a time and verify the front end. Removing a rule restores the asset instantly.

Option Content
plogins_assets_settings enabled, test_mode and the rules list
plogins_assets_seen_handles Handles recorded on the front end (not autoloaded, max 500)
plogins_assets_db_version Schema version used for upgrades

Each rule is stored in this shape:

[
'handle' => 'contact-form-7',
'type' => 'script', // 'script' or 'style'
'condition' => 'not_singular', // everywhere, front_page, blog_home, is_singular,
// not_singular, mobile, desktop, single_post_type,
// wc_shop, wc_product, wc_cart, wc_checkout
'ids' => [ 12, 34 ], // only kept for is_singular and not_singular
'post_type' => '', // only kept for single_post_type
'deregister' => false,
]

Hooks used:

  • wp_enqueue_scripts, priority 99 - records the handles of the page (administrators only)
  • wp_enqueue_scripts, priority 100 - applies the rules
  • wp_print_footer_scripts, priority 1000 - records handles enqueued later in the page (administrators only)

To keep a handle out of Pagelean’s reach, enqueue it later than priority 100 on wp_enqueue_scripts.

The plugin fires one action, plogins_assets/booted, after it has booted, with the plugin instance as the only argument. The PRO add-on uses it to register its own services. There are no filters.

Rules saved before version 1.2.0 always deregistered their handle. On upgrade they get Also deregister ticked so they keep working the same way.

Deleting the plugin removes plogins_assets_db_version and plogins_assets_seen_handles. The rules in plogins_assets_settings are removed too, unless the PRO add-on is still installed (active or not): that option is shared, so the add-on removes it when it is deleted. On multisite the cleanup runs on every site.