To create a subaddress, you need the wallet private keys. Assuming you have these, you can create them in javascript using this package, as an example.
You cannot do this only having only the public key, you need both the private keysview key and public spend key.