JSFiddle - React, Tailwind, and code Playground

by ecmanaut

JavaScript

var sampleurl = "https://camelcamelcamel.com/product/B07VPH4DNY",
		contenttype = "";

function xhrresponseheader(surl)
	{
	var xhr = new XMLHttpRequest();
	xhr.open("HEAD", surl);
	xhr.withCredentials = false;
  xhr.responseType = "blob";
	xhr.onreadystatechange = function()
		{
		if (xhr.readyState === 4)
			{
			contenttype = xhr.getResponseHeader("Content-Type");
			console.log("Content Type (XHR): ", contenttype);
			}
		}
	xhr.send();
	}

function fetchresponseheader(surl)
	{
	fetch(surl, {method: 'HEAD'}).then
		(
		function(response)
			{
			contenttype = response.headers.get("content-type");
			len = response.headers.get("content-length");
			console.log("Content Type (FETCH): ", contenttype);
			console.log("Content length (FETCH): ", len);
			}
		);
	}

xhrresponseheader(sampleurl);
fetchresponseheader(sampleurl);