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

Move q URL Parameter to hash parameters #198

Open
fregante opened this issue Dec 23, 2023 · 3 comments
Open

Move q URL Parameter to hash parameters #198

fregante opened this issue Dec 23, 2023 · 3 comments

Comments

@fregante
Copy link
Member

What's the logic between adding parameters to the hash? Is it to avoid sending unnecessary data to the server?

For simplicity, I think it would be easier to move the q parameter to the hash as well

- https://npmgraph.js.org/?q=send#deps=devDependencies
+ https://npmgraph.js.org/#q=send&deps=devDependencies

Or, if you're not afraid of the extra traffic, just use regular search parameters for all

- https://npmgraph.js.org/?q=send#deps=devDependencies
+ https://npmgraph.js.org/?q=send&deps=devDependencies
@broofa
Copy link
Collaborator

broofa commented Dec 25, 2023

What's the logic between adding parameters to the hash?

Great question. To be honest, I haven't put a great deal of thought into the current choices. It's just kind of how things have evolved. To the extent I have "principles" ..

  • Use search params for values that control the data
  • Use hash field for values that control the view
  • Minimize the risk of compromising user data

There's also a bit of pragmatism to this:

  • Changes to search params typically trigger a page reload, while the hash param doesn't. (This issue is largely mitigated by the use of the history API, but still worth keeping in mind)
  • Search params are included in the referrer header, while the hash param isn't.

The q field specifies the entry points for the graph, so pretty clearly defines the data. Hence, search param.

color, select, hide, and zoom are view settings. Hence, hash params.

deps is a hash param currently, but should arguably be search param, as it does affect the data displayed.

packages is clearly data so should arguably be a search param. But it may contain user-sensitive data, and it may also be quite large (10's or 100's of KBs). So putting it in the hash param just makes sense.

@broofa
Copy link
Collaborator

broofa commented Dec 25, 2023

While I suppose we could just stick everything in the hash, something about that feels wrong. It means the server (such as it is) never knows what graph is being rendered.

At the moment the potential change I see here is to move deps from the hash to the search params.

@fregante
Copy link
Member Author

the server (such as it is) never knows what graph is being rendered.

Why is that a problem? Isn't this a full SPA? The server always serves the same HTML page, right?

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