Skip to content

Refactor responsive video handling and improve performance#1049

Merged
JohnONolan merged 2 commits into
TryGhost:mainfrom
jessehouwing:casper/perf
Apr 24, 2026
Merged

Refactor responsive video handling and improve performance#1049
JohnONolan merged 2 commits into
TryGhost:mainfrom
jessehouwing:casper/perf

Conversation

@jessehouwing
Copy link
Copy Markdown
Contributor

@jessehouwing jessehouwing commented Apr 15, 2026

Enhance video responsiveness using CSS-only solutions, remove jQuery dependencies, and optimize loading strategies for images and scripts to improve overall performance. Implement mobile menu functionality with vanilla JavaScript.

This pull request focuses on improving performance, modernizing responsive video handling, and enhancing image loading for better user experience. The main changes include removing the legacy fitvids.js dependency in favor of a pure CSS solution, optimizing image loading with native browser attributes, and updating script loading for efficiency.

Responsive Video Handling:

  • Removed the legacy jquery.fitvids.js script and all related jQuery code, replacing it with a pure CSS solution for responsive video embeds using the aspect-ratio property. [1] [2]
  • Updated CSS to apply a 16/9 aspect ratio and full width to embedded iframes from popular video platforms, eliminating the need for JavaScript.

Image Loading Optimization:

  • Added fetchpriority="high" and loading="eager" attributes to key images (cover images, author images, and feature images) in author.hbs, index.hbs, and post.hbs to prioritize their loading and improve perceived performance. [1] [2] [3] [4] [5]

Script and Dependency Management:

  • Removed the jQuery dependency and inline script for mobile menu and FitVids initialization from default.hbs; now, only the main casper.js script is loaded with the defer attribute for non-blocking rendering.
  • Added a minimal vanilla JS snippet in init.js to handle the mobile menu toggle, replacing the previous jQuery-based approach.

Performance Improvements:

  • Updated resource preloading comments and ensured critical CSS and JS are preloaded to reduce render-blocking, as seen in default.hbs.

Pagination and Layout Enhancements:

  • Applied a 16/9 aspect ratio and overflow: hidden to the .pagination container for improved layout consistency.

Note

Medium Risk
Front-end bundle changes that alter responsive video behavior and header navigation interactions; regressions would be user-visible but are limited to theme UI/UX.

Overview
Updates the built casper.js bundle to remove the fitVids (jQuery/Zepto) responsive video logic, relying on non-JS responsiveness instead.

Adds a vanilla JS mobile burger-menu toggle that sets aria-expanded and toggles the gh-head-open body class, while leaving existing lightbox, dropdown nav, and infinite scroll behavior intact.

Reviewed by Cursor Bugbot for commit eb2898d. Bugbot is set up for automated code reviews on this repo. Configure here.

- Added aspect-ratio and overflow properties to pagination for better layout control.
- Removed jQuery FitVids library and implemented CSS-only responsive video embeds.
- Updated author images to use loading="eager" and fetchpriority="high" for improved loading performance.
- Changed script loading strategy to defer non-critical scripts, reducing render-blocking.
- Initialized mobile menu functionality using vanilla JavaScript instead of jQuery.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 431ebb0c-dc5e-4682-be9b-b8953c68f6b6

📥 Commits

Reviewing files that changed from the base of the PR and between 34c7d9d and eb2898d.

⛔ Files ignored due to path filters (1)
  • assets/built/casper.js.map is excluded by !**/*.map
📒 Files selected for processing (2)
  • assets/built/casper.js
  • assets/js/init.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • assets/js/init.js

Walkthrough

Removed the jQuery-based FitVids plugin and the jQuery 3.5.1 inclusion. Added a small vanilla JS initializer for mobile menu toggling (assets/js/init.js). Updated CSS to enforce 16:9 aspect ratios and overflow handling for article images and embedded iframes (YouTube, Vimeo, Kickstarter) and regenerated the built stylesheet. Added performance/loading attributes (loading="eager", fetchpriority="high") to several cover and author images in templates. Removed references/init code that previously invoked FitVids and the jQuery-based mobile menu.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: refactoring responsive video handling from jQuery-based to CSS-only, and optimizing performance through script/image loading improvements.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, covering responsive video handling, image loading optimization, script dependency management, and performance improvements across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
assets/built/screen.css (1)

1-1: Pre-existing CSS lint issues detected.

The static analysis hints flag several issues (deprecated word-break: break-word, grid-gapgap, vendor prefixes, etc.) that are pre-existing in the codebase, not introduced by this PR. The built output correctly reflects the source CSS changes.

Consider addressing these in a follow-up PR to modernize the CSS codebase:

  • Replace grid-gap with gap
  • Replace word-break: break-word with overflow-wrap: break-word
  • Evaluate vendor prefix removal for properties with broad baseline support
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@assets/built/screen.css` at line 1, The CSS contains legacy lint issues
(e.g., use of grid-gap, word-break: break-word, and redundant vendor prefixes)
that should be modernized in a follow-up PR: replace occurrences of "grid-gap"
(seen in selectors like .post-feed, .read-more, .site-footer .inner) with "gap";
replace "word-break: break-word" (seen on .post-card and .article) with
"overflow-wrap: break-word" and remove or update any duplicate/obsolete
vendor-prefixed rules (e.g., -ms-, -webkit- prefixes on properties already
widely supported) across the file to keep behavior identical while modernizing
syntax.
assets/js/init.js (1)

1-10: Clean vanilla JS replacement for jQuery mobile menu.

The IIFE pattern and null check are good practices. classList.toggle() is well-supported.

For enhanced accessibility, consider toggling aria-expanded on the burger button to communicate menu state to screen readers:

♿ Optional accessibility enhancement
 (function() {
     // Mobile Menu Trigger
     var burger = document.querySelector('.gh-burger');
     if (burger) {
         burger.addEventListener('click', function() {
             document.body.classList.toggle('gh-head-open');
+            var isOpen = document.body.classList.contains('gh-head-open');
+            burger.setAttribute('aria-expanded', isOpen);
         });
     }
 })();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@assets/js/init.js` around lines 1 - 10, The mobile menu toggle should also
update the burger's ARIA state for accessibility: modify the click handler on
the element referenced by the selector '.gh-burger' (variable burger) so that
after toggling document.body.classList.toggle('gh-head-open') it sets or updates
the burger's aria-expanded attribute (initialize to "false" if missing) to
reflect the new menu state (true when 'gh-head-open' is present, false when
not); ensure this is done inside the existing IIFE and preserves the null check
for burger.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@assets/built/screen.css`:
- Line 1: The CSS contains legacy lint issues (e.g., use of grid-gap,
word-break: break-word, and redundant vendor prefixes) that should be modernized
in a follow-up PR: replace occurrences of "grid-gap" (seen in selectors like
.post-feed, .read-more, .site-footer .inner) with "gap"; replace "word-break:
break-word" (seen on .post-card and .article) with "overflow-wrap: break-word"
and remove or update any duplicate/obsolete vendor-prefixed rules (e.g., -ms-,
-webkit- prefixes on properties already widely supported) across the file to
keep behavior identical while modernizing syntax.

In `@assets/js/init.js`:
- Around line 1-10: The mobile menu toggle should also update the burger's ARIA
state for accessibility: modify the click handler on the element referenced by
the selector '.gh-burger' (variable burger) so that after toggling
document.body.classList.toggle('gh-head-open') it sets or updates the burger's
aria-expanded attribute (initialize to "false" if missing) to reflect the new
menu state (true when 'gh-head-open' is present, false when not); ensure this is
done inside the existing IIFE and preserves the null check for burger.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fceac636-10df-4391-bed2-1f1ee20d2fa4

📥 Commits

Reviewing files that changed from the base of the PR and between acf1cd8 and 34c7d9d.

⛔ Files ignored due to path filters (3)
  • assets/built/casper.js.map is excluded by !**/*.map
  • assets/built/global.css.map is excluded by !**/*.map
  • assets/built/screen.css.map is excluded by !**/*.map
📒 Files selected for processing (9)
  • assets/built/casper.js
  • assets/built/screen.css
  • assets/css/screen.css
  • assets/js/init.js
  • assets/js/lib/jquery.fitvids.js
  • author.hbs
  • default.hbs
  • index.hbs
  • post.hbs
💤 Files with no reviewable changes (1)
  • assets/js/lib/jquery.fitvids.js

@JohnONolan JohnONolan merged commit f05fad3 into TryGhost:main Apr 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants