Home Web Front-end JS Tutorial Front-end image compression solution combined with Vue.js

Front-end image compression solution combined with Vue.js

Nov 03, 2016 am 09:36 AM

This is a very simple solution. Well, it's true.

Why do we do this?

Today when the mobile Web is booming, there are too many applications that require users to upload image files on the mobile Web. Because of this, we have some difficulties that we must overcome:

Low network The upload progress is slow at high speed and the user experience is poor

Under high concurrency, the background processing of larger uploaded files is stressful

Maybe there are more...

When overcoming some of the above difficulties, we can also ask ourselves some questions :

Is it really necessary to save the original images uploaded by users?

How long can users wait?

Maybe there are more...

Combined with some of the above difficulties and questions, combined with our actual cases, We may be able to do this - when the user uploads the image, the image is compressed before it is submitted to the background. After the image file size is reduced, the upload speed will naturally increase. Under the same concurrency, the background processing speed will also be improved, and the user experience will be improved.

Some children may say, why not use the form function of some mainstream CDNs to directly upload files to CDN? Of course, you can choose that plan. I just chose one among many plans to use. Or is this the nature of programmers?

Preparation

It has been said above that "when the user uploads the image, the image will be compressed before it is submitted to the background.", then let's prepare various tools immediately :

localResizeIMG (core, used to compress images on the front end)

Vue.js (process front-end data, display logic)

Bootstrap (should I say more?)

How to do it?

Upload the project After the change, use localResizeIMG for compression

Submit the data to the background in the way you want

When localResizeIMG is called, you can specify the width, height and quality of the compressed image (refer to the document for details). As for how to submit the data to In the background, you can refer to the solution mentioned in the library's wiki, everything is very simple.

Demo address

Repository address of this example

The solution in this article is not the only one, nor is it necessarily the best. If you encounter problems when using related frameworks/libraries, you can go to the corresponding Github repository to view the issue or wiki.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

jQuery Check if Date is Valid

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

jQuery get element padding/margin

Top 5 Date Manipulation JS Plugins Top 5 Date Manipulation JS Plugins Feb 28, 2025 am 12:34 AM

Top 5 Date Manipulation JS Plugins

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

10 Worth Checking Out jQuery Plugins

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

10 jQuery Accordions Tabs

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

jquery add scrollbar to div

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

See all articles