0

Is there a way to deploy some code for the web (React) and deploy another different piece of code (Vue) for mobile? Just curious. Thank you all in advance.

torotu
  • 1

1 Answers1

0

You can dynamically create script tag with src set to correct app bundle (either react, either vue):

<script type="text/javascript">
  const appScript = document.createElement('script');
  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    // Mobile, put path to vue.js app bundle
    appScript.setAttribute('src','path/to/vue/app/bundle');
  } else {
    // Desktop, put path to react.js app bundle
    appScript.setAttribute('src','path/to/react/app/bundle');
  }
  document.head.appendChild(appScript);
</script>

Note: this answer is combined from those two:

Create script on fly

Detecet a mobile device

Klimenko Kirill
  • 469
  • 5
  • 20