: Spitting server side request into HTML to be used in JavaScript bad practice? I am working with an API which essentially provides me with image urls that are hosted on a CDN somewhere. I can
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.
More posts by @XinRu657
1 Comments
Sorted by latest first Latest Oldest Best
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?
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.