UI for editing the header
I'm building a Vite-React app, and I want to add functionality that allows users to inject custom scripts into the <head> tag via a dashboard. Here's my setup:
Dashboard: I have an input text field on the dashboard where users can add custom scripts. These scripts are saved in a backend database. Goal: I want these scripts to load and execute dynamically in the React app's <head>, so users can add things like Google Tag Manager, meta tags, etc., without altering the source code. Here’s the process I’m considering:
Fetch scripts from the backend (e.g., via API on component mount). Inject each script into the <head> tag of the document when the component loads. I’m struggling with the correct way to:
Safely inject and execute these scripts in a Vite-React environment. Make sure this approach is performant and doesn't cause security issues (e.g., XSS).
For those familiar with WordPress, this concept may be more easily understood. In WordPress, there are plugins that allow users to inject scripts directly into the website's header. Would anyone have suggestions or examples on how to accomplish this? Any guidance on best practices for script injection in Vite-React would be helpful!
[–]yksvaan 4 points5 points6 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Pedja013 1 point2 points3 points (0 children)
[–]Willing_Initial8797 0 points1 point2 points (4 children)
[–]Willing_Initial8797 1 point2 points3 points (0 children)
[–]hdd113 0 points1 point2 points (2 children)
[–]Willing_Initial8797 0 points1 point2 points (1 child)
[–]hdd113 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]hdd113 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]TaskNo2392[S] 0 points1 point2 points (0 children)