omrilotan / isbot

🤖/👨‍🦰 Detect bots/crawlers/spiders using the user agent string
https://isbot.js.org/
The Unlicense
876 stars 72 forks source link

Is there a version available that doesn't require NPM? #217

Closed cvocvo closed 10 months ago

cvocvo commented 10 months ago

Steps to reproduce

We're using Umbraco (ASP.NET Core) with Smidge to deliver javascript bundles to client devices. Is there a version of isbot that doesn't require NPM?

Thank you!

omrilotan commented 10 months ago

Not at the moment but I'm open to suggestions. What alternative way would you have liked to consume the built version?

cvocvo commented 10 months ago

Thanks for the quick response; ideally just a regular old .js file would be great. Then this can be included in the Smidge bundle, however, it also opens the door to other users who are just building websites with regular <script src="/js/somejslib.js"></script> files. I'm thinking of stuff like Bootstrap where you can just pull in JS and CSS manually without the complexity of NPM and pipeline tools like ESBuild/Babel/NX. I don't know the right way to describe these JS libraries/frameworks where they're just stand-alone JS files that get included. IIFE comes to mind but I don't know if that's precisely it.

omrilotan commented 10 months ago

Would you expect this file to expose "isbot" as a global variable then (see following example)?

<script src="https://cdn.js/isbot.js"></script>
<script>
console.log(isbot(navigator.userAgent))
</script>
cvocvo commented 10 months ago

Yes that would be great

omrilotan commented 10 months ago

Okay, I've inspected JSDeliver as a CDN.

You can import and use the module on your web page already using the "mjs" version.

<script type="module">
import isbot from "https://cdn.jsdelivr.net/npm/isbot/index.mjs";

console.log(isbot(navigator.userAgent));
</script>

Other than that - I can create an iife version to be imported via JSDeliver CDN as well.

omrilotan commented 10 months ago

See https://github.com/omrilotan/isbot/pull/218

cvocvo commented 10 months ago

That's fantastic -- I will test this out! I think the IIFE version will let me drop it into Smidge. I haven't figured out how to bundle all my JS together and then import the module (because the JS is all getting loaded before via <script src=).

Update: Works great; thank you for adding support for this!

omrilotan commented 10 months ago

You can now use the iife script straight from this CDN or download it to your machines

<script src="https://cdn.jsdelivr.net/npm/isbot/index.iife.min.js"></script>