mdn / sprints

Archived: MDN Web Docs issues are tracked in the content repository.
https://github.com/mdn/content
Creative Commons Zero v1.0 Universal
150 stars 142 forks source link

What is a fragment? #3921

Closed ghost closed 3 years ago

ghost commented 3 years ago

URL(s)

https://developer.mozilla.org/en-US/docs/Web/API/Location/hash

Request type

Details

What is a fragment from "fragment identifier"? I'm talking about linking internally. It's not the JavaScript interface?

chrisdavidmills commented 3 years ago

I've updated the first sentence on page to "...the fragment identifier of the URL — the ID on the page that the URL is trying to target."

Does that make it clearer?

ghost commented 3 years ago

The ID of the element on the page. The doubt arose because reading DocumentFragment talks about an object without a parent. So I don't give how to define this element if it is appended to the DOM.

However personally fragment sounds better to me, a piece of document in short.

There is a page for fragment not the interface?

chrisdavidmills commented 3 years ago

Hrm, this is an interesting point, and I'm not surprised you found it confusing. I think a DocumentFrgament is a different thing — an object that represents a generic DOM node that hasn't been inserted into the DOM yet. If you look at the example on the DocumentFragment page, it uses one such object to contain several list items, before the fragment is then inserted as a child of the unordered list.

If you look at the HTML tree of the example, you don't see it as an extra node in the hierarchy — the list items are direct children of the unordered list after they have been appended.

I am not sure why you'd do this rather than just appending them directly to the unordered list. Maybe it is more efficient to append fewer items to the visible DOM?

ghost commented 3 years ago

I think DocumentFragment is ok. It's the word fragment in hash that sounds confusing because It points to actually Elements and not Fragment (Fragment not exists). Isn't It?

Seems DocumentFragment exists to perform operation without repaint like virtual DOM does? 🤷🏻‍♂️ It's rational to have a kind of RAM 🧐

ghost commented 3 years ago

From the spec:

A URL’s fragment is either null or an ASCII string that can be used for further processing on the resource the URL’s other components identify. It is initially null.

So It was right as is... 🤔

ghost commented 3 years ago

Seems It was right. I was confused by the fact that hash is not the fragment. fragment is defined in the URL spec but not in the URL interface. Probably to obtain a string to pass to querySelector instead of getElementById 🤔 What was looking for Is the string without # so You can Say that that string should match an id attribute.