@mts-pjsc/image-optimize 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# React component for using optimized images in the browser.
|
|
2
|
+
|
|
3
|
+
Works in conjunction with the [Image Optimizer](https://github.com/MobileTeleSystems/image-optimize).
|
|
2
4
|
|
|
3
5
|
Optimizing images helps reduce image weight and increases website loading speed, which is very important for both users and search engines. For these purposes, we have created a microservice that perfectly copes with this task.
|
|
4
6
|
|
|
@@ -12,38 +14,17 @@ Features:
|
|
|
12
14
|
- Supports basic authorization for multiple domains and endpoints,
|
|
13
15
|
- Supports security restrictions for allowed addresses.
|
|
14
16
|
|
|
15
|
-
###
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
docker run -it --rm -p 3000:3000 mts-optimize
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Now you can open the browser and check the work with the command:
|
|
22
|
-
```sh
|
|
23
|
-
http://localhost:3000/optimize?size=1060&format=webp&src=https://tb.mts.ru/static/landing/images-index2/banner/slider/partners.png
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
By changing the src, size, format parameters, you can choose the path to the image, the final size and the image format.
|
|
27
|
-
|
|
28
|
-
### Use
|
|
29
|
-
To start the microservice in production, use the command:
|
|
30
|
-
```sh
|
|
31
|
-
docker run -d --restart always -p 3000:3000 mts-optimize
|
|
32
|
-
```
|
|
17
|
+
### Before use
|
|
18
|
+
[The optimization microservice](https://github.com/MobileTeleSystems/image-optimize) must be deployed on the server along the path `/optimizer`. React component will use it.
|
|
33
19
|
|
|
34
|
-
###
|
|
35
|
-
- `-e PORT=3000` - the port on which the microservice will be launched, default 3000.
|
|
36
|
-
- `-e ALLOW_SIZES="100,200,1024-1920"` - an array of allowed sizes for the resulting images, default 100-1920. Use specific values to prevent heavy loads on the server.
|
|
37
|
-
- `-e ALLOW_SOURCES="https%3A%2F%2Ftb.mts.ru%2F"` - url array of allowed addresses for image sources, default * (any). Use comma as separator. It is recommended to apply encodeURIComponent to url.
|
|
38
|
-
- `-e BASIC_AUTHS="https%3A%2F%2Ftb.mts.ru%2F"` - an array of endpoints with basic authorization parameters, default empty. Has format encodeURIComponent("url"):login:password. Use comma as separator.
|
|
20
|
+
### Using
|
|
39
21
|
|
|
40
|
-
|
|
41
|
-
Right now you can use sample from the ./components-samples/ReactLazyImg.ts(add link after publishing) file. Just copy the file to your project and use it. The component inherits interface of the html img element. The component automatically check the most suitable picture in size and formats supported by the browser and selects the most optimal picture for display.
|
|
22
|
+
Just replace the \<img\> element with the Image component from the package. The component is fully compatible with the \<img\> element. Next, the component will do all the magic on its own.
|
|
42
23
|
|
|
43
|
-
Sample
|
|
24
|
+
Sample:
|
|
44
25
|
```typescript
|
|
45
|
-
<
|
|
46
|
-
alt="Sample of work
|
|
26
|
+
<Image
|
|
27
|
+
alt="Sample of work Image Optimizer"
|
|
47
28
|
src="/static/landing/images-getmeback/phone-fon.png"
|
|
48
29
|
/>
|
|
49
|
-
```
|
|
30
|
+
```
|