I have multiple background images used in my CSS. Best practice for this used to be to combine images into a single sprite sheet to reduce the number of HTTP requests.
From looking at the Create React App documentation there is no mention of sprites. Instead it recommends importing images directly into CSS:
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-images-fonts-and-files
As a test I've done this. So a React component's CSS looks like this:
.component {
&:before {
background-image: url('./img/account.svg'); // This image is within the React component's folder
}
}
From looking at my network tab I can multiple images:
However when I use the dev tools to simulate a slow connection the images all appear at exactly the same time. This makes me wonder if in fact there are not multiple HTTP requests and Webpack is doing this performance optimisation some other way?
So to summarise my question: If I were to combine my background CSS images into a single sprite sheet, would this decrease the number of HTTP requests and therefore improve performance?
You can find an answer here in the CRA document:
To reduce the number of requests to the server, importing images that are less than 10,000 bytes returns a data URI instead of a path. This applies to the following file extensions: bmp, gif, jpg, jpeg, and png. SVG files are excluded due to #1153.
https://facebook.github.io/create-react-app/docs/adding-images-fonts-and-files
Related
There is any possibility to upload a file with different sizes in DropzoneJs?
I'm using vue-dropzone which is made with dropzonejs and i have to upload the same file with different sizing for srcset.
Example:
I want to upload the file test.png which is 1000x500 px. There is any possibility to upload it at the same time in original resolution and also in 500x250px?
Image resizing in the browser has been a seat-of-the pants experience for a long time. Web assemblies are the way of the future for processing-intensive tasks in web apps. I came across this project the other day. It looks fantastic and I really can't wait to strip out our home-baked image resizing with canvas and replace it with this.
The usual reason for doing this is to avoid large uploads. It's a little bit weird to want to resize in the browser then upload the original. You might be better resizing on the server. You'll save bandwidth and the server libraries will be more mature than what's available on the client.
Along with the original image object you can add one more your custom resized image to the array of images by using resize config of dropzone. You can do the above on drop event or adddedFile event of dropzone.
I have an Image that I've downloaded and saved to the path /data/user/0/com.project/files/assets/image.png and I want to use this in my Image component in React-Native. Is there a way to use images stored in this path?
Ways to solve it that I have knowledge of but cannot use :
using require. which basically accepts literal strings that is not what I want for non-static images. names may change as per image for a single image source
using Native bundles, which is again I cannot use as the images are first being downloaded and then is being used.
using http links directly.which as again I cannot use as my feature states that the App cannot rely on network as it needs to render images in offline mode as well
If it's a file on your device, I think the way of displaying it is somewhat like this:
<Image source={{uri:'file:///data/user/0/com.project/files/assets/image.png'}} style={{width: 100, height: 100}}/>
Just make sure the file path is from the root. Hope it works for you.
I'm evaluating Fine Uploader compared to various other options, specifically JQuery File Upload.
I generally prefer the Fine Uploader approach as it's more lightweight, compared to JQuery File Uploader which has dependencies on Bootstrap and JQuery UI.
However it's important to be able to resize images: e.g., a user may select a large file from their camera and this may be very large - uploading the full resolution photo may take a very long time. JQuery File Upload doe this.
Additionally we don't have much use for very high resolution files.
If possible (I'm aware some browsers may not support this), I'd like to be able to resize images client size.
Is this possible?
Fine Uploader does not currently have any native support for image manipulation. This is a feature in our backlog, but we have not had many users tell us they are interested in this. This is one of the reasons why such a feature has yet to be implemented natively. There is a case, #707 that marks the start of native image-editing support for Fine Uploader. It is tentatively scheduled for 4.0.
However, you can certainly make use of FileReader and Canvas to resize the image. You can then submit this resized image as a Blob to Fine Uploader via the addFiles API method. At that point, the file has been submitted and Fine Uploader is ready to upload the item.
Essentially, the steps you would follow to handle this specific scenario, before Fine Uploader natively supports image manipulation:
Provide your own file input element(s) or make use of Fine Uploader's file/folder drag and drop support to get a handle on some files selected by the user.
Use FileReader to read the contents of the image.
FileReader will provide you with a URL for the image, assign that to the src attribute of an img element.
Draw the img onto a canvas element. This is where the resizing occurs.
Grab the URL of the resized image from the canvas element (canvas.toDataURL(...)).
Convert the URL to a Blob.
Pass the Blob to the addFiles API method of Fine Uploader.
The intent is to take care of most if not all of this for integrators such as yourself in the future by adding native image manipulation support to Fine Uploader.
Hope this helps.
I am dynamically creating some controls in a page. it will become slow when we have some fifty controls.
what are the code optimization techniques/ guideline used in extjs?
Is there any specific methods which will slow down the entire loading?
Sencha has great posts:
Ext JS 4.1 Performance about:
Network latency which affects initial startup time heavily, but also data store load time.
CSS processing.
JavaScript execution.
DOM manipulation.
Optimizing Ext JS 4.1-based Applications about optimization tips and the Page Analyzer tool.
My tips are
Use Ext.container.Container rather than Ext.panel.Panel.
Instead of adding ext components, use XTemplate with data view to load similar controls.
if you are using many images then use image sprites - An image sprite is a collection of images put into a single image. A web page with many images can take a long time to load and generates multiple server requests.
Using image sprites will reduce the number of server requests and save bandwidth.
http://css-tricks.com/css-sprites/
Is there any way to resize pictures while uploading them in Symfony2 ?
The ImagineAvalancheBundle only allows to resize images to thumbnails when retrieving them, which is not really performant to me.
Besides, the UploadedFile object retreived when posting data doesn't seems to have resizing methods...
Any Idea ?
I had the same problem you are asking for.
The main issue is that the bundle resizes and/or crops the images directly.
So that can take a lot of time with big images and if many images are expected per page.
So I've fix this issue by calling directly after imageupload the resize() function to the image.
Hence, I save (copy) the resized image to the filesystem at the server. Obviously I store the path of the image into the database to can load it directly if needed.
I tried the included memcache of the imageresize bundle but in my case it doesn't work.
I had the same problem for a project that i'm actually developing. I searched a lot on the net and found nothing realy performant and also easy to use for non-tech people.
I created a bundle to be able to upload with jquery file upload and crop with jcrop with some other functions.
ComurImageBundle
What is exactly your goal ? Resize and crop ? Other ?
I don't understand why you say that the bundle resize to thumbnail only as you can define precisely your resize preset through config :
# app/config/config.yml
avalanche_imagine:
filters:
my_thumb:
type: thumbnail
options: { size: [120, 90], mode: outbound }