-2

I created an app with angularjs and bootstrap. The content is served by a backend. There are also dynamic images served as links. They can be requested from the backend is different width sizes.

Question: how can I detect the users screen max-width before requesting data from the backend? So that the backend will respond with links to smaller images?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

3 Answers3

1

using jquery you can get the viewport size.

var viewport = $(window).width();

$('#viewportSize').html(viewport);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="viewportSize"></div>
xergio
  • 44
  • 6
  • Wouldn't it be sufficient to just check `$(window).width() < 320` eg if I want to know if screen size if very low? Or is it advised to use a div element? – membersound Jun 20 '16 at 11:10
0

HTML doesnt submit screen options by request. You need to create a hidden field on front end and send it back to server with a value you need with. There is no other way for backend to calculate the width of the screen in anyway that I know.

See this ASP.NET Get Screen Width

Community
  • 1
  • 1
Demeter Dimitri
  • 608
  • 8
  • 17
  • It would be sufficient for the frontend to calculate the width, and send this value in the get query for the content to the backend. – membersound Jun 20 '16 at 07:17
0

The <picture> element allows you to load different content images based on media queries.

<picture>
  <source 
    media="(min-width: 650px)"
    srcset="images/kitten-stretching.png">
  <source 
    media="(min-width: 465px)"
    srcset="images/kitten-sitting.png">
  <img 
    src="images/kitten-curled.png" 
    alt="a cute kitten">
</picture>

Further reading:

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • But this works for statically known images only. I get the images, as written, dynamically from the backend, in the size I request. – membersound Jun 20 '16 at 07:22