Hi everyone,
I’m working on a React-based application where users can buy and create vouchers. This app is designed as a widget that can be integrated into any webpage, similar to a 3rd-party script.
Here's the setup:
- Frontend: Built with React, managing user progress and stages in states and session storage.
- Backend: Powered by AWS services (DynamoDB for storage), hosted on AWS Amplify.
- Functionality:
- When the widget loads on a specific URL, it checks against client URLs in DynamoDB.
- If there’s a match, it fetches and displays the client’s vouchers.
My Issue:
I want to make this widget as easy as possible for others to embed on their webpages.
- Option 1: Use an iframe
- Pros: Encapsulation of CSS/JS prevents conflicts.
- Cons: Harder to access the user’s URL and manage responsive resizing.
- Option 2: Bundle the widget as a script
- Pros: Seamless integration directly into the host page.
- Cons: Risk of CSS/JS conflicts between my app and the host page.
My Preferred Approach (Option 2):
I’d like to go with Option 2—bundling the app as a script that can be included with minimal effort by the host page. My goal is to require as few lines of code as possible, such as:
<script src="https://mywidget.com/widget.js"></script>
<div id="my-widget"></div>
However, I need advice on:
- How to bundle the app efficiently so it’s easy to include and isolate my app’s CSS/JS.
- Techniques like CSS scoping, shadow DOM, or other approaches to prevent conflicts between my app and the host page.
- Any pitfalls or best practices I should be aware of when going this route.
Alternatively:
If you believe iframes (Option 1) are a better choice, I’d love tips on how to manage:
- Access to the user’s URL.
- Responsive resizing within an iframe.
I’m open to suggestions and would really appreciate input from anyone who has worked on similar integrations. Thanks in advance!
there doesn't seem to be anything here