Download specific .dart file depending on media

I know that you can load a specific CSS file depending on the type of media, but is it possible to do the same for a dart file?

For example, I want to load a specific dart file depending on whether the media type is β€œpocket” or β€œscreen”

+4
source share
1 answer

To answer my own question, this can be done, but not through the media. The solution is to dynamically load the correct script:

<script> var scriptSrc = 'firstScript.dart'; if (screen.width <= 800) scriptSrc = 'secondScript.dart'; var script = document.createElement('script'); script.type = "application/dart"; script.src = scriptSrc; var body = document.getElementsByTagName('body')[0]; body.appendChild(script); </script> 
+1
source

All Articles