- Issue created by @prudloff
- First commit to issue fork.
- π¦π·Argentina tguerineau
I've been working on the feedback provided and have made some updates to the module in a new branch. Here's a brief summary:
1. DOM Parsing over Regex: I've switched the logic from using regex patterns to a DOM-based approach. This helps in addressing the limitations of regex in parsing HTML and provides a more robust and flexible way of handling different
<link>
tags in the document.2. Maintaining
<link>
attributes: The new changes ensure that attributes such as media are retained when the<link>
tags are modified.3. Selective Handling of External Links: The new logic respects the
css_defer_external
setting, ensuring that only the desired links (either internal, external, or both) are deferred based on the configuration.I've pushed these updates to a new branch on the issue fork.
Testing: I've conducted preliminary tests, and the changes seem to work as expected. However, I'd appreciate it if others could also test and share their feedback.
I kindly request everyone to review the changes. I believe these changes address the concerns raised in this issue, but I'm open to further improvements.
- Status changed to Needs review
about 1 year ago 4:37pm 12 September 2023 - @tguerineau opened merge request.
- π¦π·Argentina tguerineau
Hi @prudloff,
I've been working on implementing a solution for deferring scripts effectively using the suggested
Html::load()
andHtml::serialize()
methods. The initial approach we discussed seemed promising, but during implementation and testing, we've encountered some significant challenges that I'd like to outline:- Document Structure Changes: Utilizing
Html::load()
for the entire document inadvertently modifies the structure. Specifically, elements that are originally in the<head>
tag are being moved into the<body>
tag. This is problematic as it alters the expected layout and behavior of the page, leading to visual discrepancies and potential functional issues. - DOM Manipulation Side Effects: In an attempt to circumvent the above issue, I tried various methods to isolate the manipulation to the
<head>
content. This included wrapping content in temporary containers and placeholders to maintain structure. Unfortunately, these methods introduced additional complexity without resolving the core issue - thatHtml::load()
andHtml::serialize()
are not preserving the placement of head elements when serializing the document back to HTML. - First Approach Functionality: It is worth mentioning that the initial non-DOMDocument approach we developed does not encounter these structure-related issues and works as expected. It effectively transforms the
<link>
elements for CSS without disrupting the document structure.
Given the problems faced with the current
Html::load()
andHtml::serialize()
strategy, I propose revisiting the initial approach for further consideration. It offers a stable solution with the desired functionality without compromising the document's integrity.I am open to feedback and any suggestions on alternative methods.
- Document Structure Changes: Utilizing
- Status changed to Needs work
9 months ago 2:53pm 15 February 2024