Skip to content

Remove server roundtrip for window dimension code - #7

Merged
derickr merged 1 commit into
php:masterfrom
mattstauffer:mes/fix-window-sizing
Nov 24, 2026
Merged

derickr merged 1 commit into
php:masterfrom
mattstauffer:mes/fix-window-sizing

Conversation

@mattstauffer

Copy link
Copy Markdown
Contributor

In the proposed PHP homepage redesign (php/web-php#2105), we're linking to various URLs in the history of the project, which led me to: https://talks.php.net/show/oscon2002/

We're having an issue there where, sometimes, the slide pages get stuck re-loading forever.

Here's what I think is going on:

Slide pages under /show/* specifically have this issue, because there's code trying to get the dimensions. When PHP sees no dims cookie, keyboard.js.php emits a call to get_dims(), which in getwidth.php sets the cookie and then calls location.reload() immediately.

However.

AFAICT, the move to BunnyCDN has happened since anyone last really interacted with this code much, so no one noticed that the new CDN rules have slide pages coming back as cache-control: public, max-age=3600 with cdn-cache: HIT, cached regardless of cookies.

So what that means for us is: if a cookie-less visitor visits and fills the cache, every visitor after that gets the copy containing the reload call, and each reload returns that same copy (with the reload call) until the entry expires.

To reproduce: with no cookies, request a slide (try with a cache-busting query string, e.g. ?cb=123) and the onload handler contains a call to get_dims();, while the cached copy of the same slide may or may not, depending on who populated it.

Proposed fix:
Stop handling the window size through a cookie.

The size is only used in a few places that I could find, nearly all of them already JavaScript:

  • the slide-list popup position and height in display.php (inside onClick strings)
  • the slide-in animation offset in keyboard.js.php,
  • the Flash widget width in flash mode, which can take a fixed default

Replacing those with window.innerWidth / window.innerHeight lets getwidth.php, the get_dims() call, and the cookie parsing in show.php be deleted, with no CDN change needed. It also fixes winH, which is currently always 0 because show.php checks $winH instead of $mode->winH; I believe this will fix an issue that may otherwise present with our popups.

Separately, slide pages still depend on the session for the selected display mode, so a cached slide can be served in another visitor's mode; that is out of scope here but worth noting.

@derickr
derickr merged commit 4a7cc78 into php:master Nov 24, 2026
@mattstauffer
mattstauffer deleted the mes/fix-window-sizing branch November 24, 2026 18:22
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