![]() ![]() ![]() Have your cake and eat it too In the above image the file size is reduced by more. The result better PNG files with 100 support for transparency. All unnecessary metadata is stripped too. Note: Keep in mind that when you do Ajax requests, you are restricted by the Same origin policy, which allows you to make requests only within the same domain.ġ.) About the Content-Length, I think that a size mismatch could happen for example if the server response is gzipped, you can do some tests to see if this happens on your server.Ģ.) For get the original dimensions of a image, you could create an IMG element programmatically, for example: var img = document. By reducing the number of colors, 24-bit PNG files can be converted to much smaller 8-bit indexed color images. ![]() This kind of request is used to obtain metainformation about the url implied by the request without transferring any content of it in the response.Īt the end of the HTTP Request, we have access to the response HTTP Headers, including the Content-Length which represents the size of the file in bytes.Ī basic example using raw XHR: var xhr = new XMLHttpRequest() Īlert('Size in bytes: ' + xhr.getResponseHeader('Content-Length')) To get the size of a file hosted on the server, you could simply make an HEAD HTTP Request using Ajax. Now to get the file size, now I can only think about the fileSize property that Internet Explorer exposes for document and IMG elements. var img = document.getElementById('imageId') To get the current in-browser pixel size of a DOM element (in your case IMG elements) excluding the border and margin, you can use the clientWidth and clientHeight properties. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |