Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be server-side-rendering friendly #39

Open
mmkal opened this issue Sep 25, 2023 · 1 comment
Open

Be server-side-rendering friendly #39

mmkal opened this issue Sep 25, 2023 · 1 comment

Comments

@mmkal
Copy link
Contributor

mmkal commented Sep 25, 2023

Hi @dwmkerr and/or @pvspain - curious if this has come up so far. I'm using crosswords-js on a react application, and have noticed there can be a lag between page load and the crossword being rendered. I think that part of this is the cost of iterating through the clues, validating them, and calling document.createElement(...) for the grid, for each cell, and for each clue.

It's very useful to have the signature of the CrosswordController class just be a model and two elements for the grid and the clues, for getting started quickly. But it'd be useful to be able to pass fully-hydrated HTML element references in, and just have the controller attach the various event handlers/callbacks. That way, the crossword itself could be server-side rendered, cached, and loaded instantly, with the support for interactions coming after the user loads the page.

It might be possible to implement as simply as moving all the document.createElement(...) calls to a method, and call it conditionally, based on whether the dom element looks to be ready already or not:

class CrosswordController {
  constructor(crosswordModel, domGridParentElement, domCluesParentElement) {
    const domElementsReady = this.checkIfDomElementsAreReady(domGridParentElement, domCluesParentElement)
    if (!domElementsReady) {
      this.createView()
    }
  }

  createView() {
    this.#crosswordGridView = this.#document.createElement('div');
    // create cells, clues elements, add classes etc. etc.
  }
}

Then it'd allow people using this library to do things like generate the HTML once when a puzzle is uploaded to a dashboard, and serve that HTML much faster to users when they use it - the structure will look the same for all users.

@pvspain
Copy link
Contributor

pvspain commented Oct 1, 2023 via email

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

No branches or pull requests

2 participants