Skip to content

add defer attribute to script tags for improved loading performance#3750

Open
RynoCODE wants to merge 1 commit intopi-hole:developmentfrom
RynoCODE:master
Open

add defer attribute to script tags for improved loading performance#3750
RynoCODE wants to merge 1 commit intopi-hole:developmentfrom
RynoCODE:master

Conversation

@RynoCODE
Copy link
Copy Markdown

Thank you for your contribution to the Pi-hole Community!

Please read the comments below to help us consider your Pull Request.

We are all volunteers and completing the process outlined will help us review your commits quicker.

Please make sure you

  1. Base your code and PRs against the repositories developmental branch.
  2. Sign Off all commits as we enforce the DCO for all contributions
  3. Sign all your commits as they must have verified signatures
  4. File a pull request for any change that requires changes to our documentation at our documentation repo

What does this PR aim to accomplish?:

PR aims to improve the page load performance and rendering speed of the Pi-hole web interface by ensuring non-critical scripts do not block the initial HTML parsing.

How does this PR accomplish the above?:

Added the defer attribute to <script> tags across the HTML/PHP templates. This allows the browser to continue parsing the DOM while the JavaScript files are being downloaded in the background, executing them only after the document has been fully parsed. This increases the speed for render load.

Link documentation PRs if any are needed to support this PR:

NA


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

Signed-off-by: RynoCODE <74398242+RynoCODE@users.noreply.github.com>
@RynoCODE RynoCODE requested a review from a team as a code owner March 28, 2026 17:31
@yubiuser
Copy link
Copy Markdown
Member

Thanks for your contribution. We had a PR adding defere in the past, but it needed to be revereted because it caused TypeErrors. We need to test this properly.

@RynoCODE
Copy link
Copy Markdown
Author

RynoCODE commented Mar 29, 2026

Thank you for providing that context. After reviewing the project history, specifically Issue #3302 and PR #3382, which reverted the initial attempt in PR #3295, the root cause of the issue is clear. The TypeErrors arise because the defer attribute delays script execution until the DOM finishes parsing. Currently, the project's JavaScript files are distributed across various .lp view templates rather than being centralized. As a result, introducing defer disrupts the execution sequence for critical dependencies like jQuery, which must load synchronously to support these fragmented templates. I think the scattered js needs to be centralised which will also help in long term development.

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

Successfully merging this pull request may close these issues.

2 participants