Does anyone know how to make an embedded snippet o...
# random
d
Does anyone know how to make an embedded snippet of Javascript for other peoples websites?
Copy code
<scripts src="my-cool-embed.bundled.js"></script>
Is that just some kind of minified JS that’s stored in an s3 bucket and the access is by… I guess URL? I don’t really understand the architecture of how something like that would work.
t
Yeah you can do that, you can even use our static site to ship it with a cdn
Someone in here was doing that recently
I'd suggest using
rollup
to bundle your code into various formats
d
Ok. So then that scripts hits my API which then also validates the request headers?
d
This is what one of my companies do. We provide 3D viewers that our customers embed on their websites. In short, our customer will embed:
Copy code
<our-viewer id="abc"></our-viewer>
<script src="<https://cdn.example.com>" async></script>
Our script will find and initialise that component. We build our codebase with webpack (or similar) and then copy it to s3 in a version folder:
/public/v1.0.1/main.js
Then we have a cloudfront distribution that points there. We have a folder /latest that points to the latest version and that we change the “target” every deployment We keep versions in case some new version would introduce some unwanted side effect. This allows the user to target another version if needed
<script src="<https://cdn.example.com/v1.0.0/main.js>" async></script>
At the moment, this company does not use SST, lately I have tried SST intensively in order to migrate that company to it and so far, I have tried a static Site - works ok but I lost the versioning. We have tried as well a simple bucket + a Cloudfront distribution and using BucketDeployment construct from cdk. Works well. We haven’t finish the whole implementation yet. One gotcha - BucketDeployment has changed and now you have to allow PutObjectAcl to your bucket for it to work. We do it this way:
Copy code
this.modelsBucket.s3Bucket.grantPut(new iam.AnyPrincipal());

this.modelsBucket.s3Bucket.grantPutAcl(new iam.AnyPrincipal());
Not sure how good this is, but at least it works now.
d
Thanks Daniel. This is super helpful