I am working with an API which essentially provides me with image urls that are hosted on a CDN somewhere. I can simply pass it a number and it will give me the right image and it also provides me some information about that image.

Working in PHP, I have a way to curl the request pretty easily (security is not an issue because nothing on this CDN is actually private information -- it's just for convenience sake) so that I can show the content and load it.

However, there are some parts that I would ideally need to use JavaScript for -- one example is the CDN hosts retina images and I need a good way to show the retina image and therefore need the pixel ratio (usually I could just use a media query but I'm requesting the image so I don't know it) so I could use JavaScript's matchMedia to do that.

My actual question: I was thinking of rather than making another separate AJAX request in JavaScript for the same information (server side I need to load some of the content anyways) I was thinking I could spit out the information into a hidden HTML tag like almost like a <input type="hidden" /> that I can just get via JavaScript. This way I don't have to make an extra request but I was wondering if this might be bad practice? Can this affect SEO? I feel like I am not thinking of some things as why I may not want to do this.

  • Is this an image referenced in the CSS, or in the HTML content? – MrWhite Dec 9 '15 at 21:55

I can't see any problem with this. The content is essentially meta-information and will simply be ignored SEO-wise.

However, since this is to be read/processed by JavaScript, why not simply output a JS object (in a <script>) from the get go?

  • That's not a bad idea. I might try this if there are no other answers. Thanks a lot for your input :) – aug Dec 9 '15 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.