Jump to content

Make dynamic "new posts" comply with the HTML spec


Feld0

Recommended Posts

IPS staff, please refer to ticket #835988.

The feature that notifies users of new posts in a topic made while writing a response (and subsequently allows the user to view them) is not compliant with the HTML spec, which breaks the feature when running IP.Board through a minification mechanism such as CloudFlare's before serving it to the user.

This happens not because the minifier breaks something, but because the feature relies on post ID's stored in HTML comments that it parses client-side to function. The minifier is the component compliant with the specs here, as the W3C stipulates that the contents of HTML comments should have no functional purpose. Here is the relevant snippet from the post template:

<!--post:{$post['post']['pid']}-->
<if test="sDeleted:|:$post['post']['_isDeleted'] AND $post['post']['_softDeleteSee']">
	{parse template="softDeletedPostBit" group="topic" params="$post, $displayData['sdData'], $topic"}
</if>
<if test="sDeletedNot:|:! $post['post']['_isDeleted']">
	<div class='post_block hentry clear clearfix <if test="isSolvedCss:|:$post['post']['_isMarkedAnswered']">solved</if> <if test="postQueued:|:$post['post']['_isHidden']">moderated</if>' id='post_id_{$post['post']['pid']}'>

It's understandable that the post ID needs to be in the HTML source somewhere for the feature to function, but putting it in a comment is fundamentally wrong. The better approach, to stay within the specs and allow compliant minifiers to be used, is to put this information in a custom data attribute, which was designed precisely for this purpose and is rightfully left alone by minifiers.

Link to comment
Share on other sites

  • Management

Absolutely, we'll make better use of data- attributes when we rewrite the templates for 4.0

However, in the short term, each post parent DIV has an ID with an attribute in the format:

"id='post_id_{$post['post']['pid']}'"

Will that suit your needs?

Link to comment
Share on other sites

Absolutely, we'll make better use of data- attributes when we rewrite the templates for 4.0

However, in the short term, each post parent DIV has an ID with an attribute in the format:

"id='post_id_{$post['post']['pid']}'"

Will that suit your needs?

Glad to hear that, Matt. :)

Making the script use the div's ID to retrieve the post ID will function perfectly as an interim solution. If that works well, adding the post ID to a data- attribute as well may even be unnecessary if the former can reliably be extracted from the div ID.

ıf you are using a customisation and that customisation breaks something on main script , you should get your customisation script fixed imo.

That's not really the concern here; disabling the minifier can and does work to make IPB's script work as intended again. The problem is that IP.Board is violating the specifications of HTML by putting meaningful data in comments in the first place. The minifier I use strips out comments from the HTML source because comments are functionally meaningless by definition. Removing the minifier makes IPB function correctly again, but it doesn't make it any less dependent on HTML comments for meaningful functionality.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
×
×
  • Create New...