Embodiment
The exemplary embodiment of the disclosure is more fully described below with reference to accompanying drawings.Although showing the disclosure in accompanying drawing
Exemplary embodiment, it being understood, however, that may be realized in various forms the disclosure without should be by embodiments set forth here
Limited.On the contrary, these embodiments are provided to facilitate a more thoroughly understanding of the present invention, and can be by the scope of the present disclosure
Complete conveys to those skilled in the art.
The embodiments of the invention provide a kind of method of client downloads picture, methods described is applied to client-side, such as
Shown in Fig. 1, methods described mainly includes:
101st, when the browser that client is embedded sends picture download request to server, using belonging to the client
The primary code of operating system intercepts and captures the picture download request.
Wherein, different operating system may use different primary codes.For example, when operating system is iOS system,
Primary code is ObjC (Objective-C expands C Object-Oriented Programming Language);It is former when operating system is Android system
Raw code is Java.
When user, which is based on client, accesses webpage, the embedded browser of client or the affiliated operating system of client
Primary code can HTML (HyperText Markup local from client or server side acquisition webpage to be visited
Language, HTML) data, then the html data is parsed and rendered by browser.When to be visited
Webpage in when containing picture, due to recorded in html data be only picture network address, and the not substantive content of picture,
So when browser determines in html data the network address containing picture, can be first according to each picture recorded in html data
Network address generates corresponding picture download request respectively, is then turned on most two threads and sends different pictures to server successively
Download request.Now, the Thread Count that can be opened due to browser is less, so that picture download efficiency is relatively low, so this
Inventive embodiments use the primary code of the affiliated operating system of client when browser sends picture download request to server
These picture download requests are intercepted and captured, come and be sent to server to send under multiple pictures so that primary code reopens more multithreading
Request is carried, to improve picture download efficiency.
It should be noted that " the embedded browser of client sends picture download request to server " that this step is related to
Concrete scene do not limit.For example, browser can be based under the scene downloaded on demand to server send picture download
Request or based under the non-scene downloaded on demand to server send picture download request.Wherein, download pictures on demand
Refer to:It is not that all pictures in webpage are first locally downloading further according to display need before being rendered to web data
Ask and shown, but demand is directly shown come download pictures according to picture, i.e., when picture tag enters screen just to service
Device sends picture download request.It follows that due to each picture in not webpage have into screen chance (for example,
User is based on client and opened after webpage, may not scroll down through the page, the link just shown by clicking in screen is redirected
Another page has been arrived, or has directly closed current page), so the method for download pictures can save picture download on demand
Flow.In addition, on realizing that the specific implementation of the present invention can refer to Fig. 3 scene implementation in the case where downloading scene on demand
Example.
102nd, the primary code opens at least one new thread and the picture download request is sent into the server.
After primary code intercepts and captures the picture download request that browser is sent to server, browser and service can be interrupted
Data interaction between device, then by opening the data interaction between primary code and server, realizes picture down operation.
Specifically, because the primary code of the affiliated operating system of client is Multi-core mechanism, so when primary code intercepts and captures clear
, can be according to the number of the picture download request of intercepting and capturing, to be opened into after the picture download request that device of looking at is sent to server
Picture download request is sent to server by a few new thread again.For example, picture download request number can be caused and new
Number of threads is into positive correlation, i.e. the number of picture download request is more, then make it that the new thread number opened is more.
103rd, the primary code receives the image data that the server is returned.
, can be with after multiple picture download requests are concurrently sent to server by primary code based at least one new thread
Pass through URL (Uniform Resource of at least one the new thread the reception server in picture download request
Locator, URL) image data that finds.
It should be noted that the image data that primary code is received from server side is probably the original that can be directly displayed
The image data of beginning, it is also possible to original image data is compressed, encapsulated etc. after processing be easy to transmission but can not be straight
Connect the image data of display.For example, original image data is the data of bitmap forms, for speeding up data transmission speed,
Image data to be sent is first converted to the data of jpeg forms by server by bitmap forms, then by the jpeg forms
Image data be sent to primary code.
104th, the image data is sent to the browser and shown by the primary code.
Referred in above-mentioned steps 103, the image data that primary code is received from server side be able to may directly show
Show, it is also possible to can not directly display, it is therefore desirable to which client will first receive the figure that image data is converted into directly displaying
After sheet data, then browser is allowed to show it.
The specific implementation for allowing browser progress picture to show can be largely classified into following two:(1) primary code is straight
Connect the image data that will be received and be sent to browser, it is directly first by browser so as to when image data can not be directly displayed
The image data that image data is converted into directly displaying, then the image data that can be directly displayed is shown;(2)
Primary code can first judge that the image data that server is returned whether can when receiving the image data of server return
Directly display, if can directly display, the image data for directly returning to server is sent to browser and shown, if not
It can directly display, then the image data that server is returned first is converted into the image data that can be directly displayed by primary code, so
The image data for being possible to directly display again afterwards is sent to browser and shown.
For the second way, because when the picture download request of intercepting and capturing is more, primary code is probably one by one
Ground receives all image datas, and and it is non-disposable receive all image datas, so now primary code is opened
At least one new thread may still carry out picture down operation.Therefore, in order to improve the effect of image data format conversion
Rate, primary code can separately open the image data for returning to server independently of other threads of at least one new thread and turn
Change the image data that can be directly displayed into.
The method of client downloads picture provided in an embodiment of the present invention, the browser that can be embedded in client is to service
When device sends picture download request, first using the primary code for the affiliated operating system of client that can open more multithreading simultaneously
The picture download request is intercepted and captured, then by primary code according to default download mechanism, opening at least one new thread should
Picture download request is sent to server, (for example, when the picture download request of intercepting and capturing is more, can open multiple new threads
These picture download requests are concomitantly sent to server), last primary code receives the image data of server return
Afterwards, the image data can be sent into the embedded browser by primary code to be shown.It follows that and prior art
In directly compared by the less embedded browser download pictures of Thread Count can be opened, the present invention by intercept and capture browser send
Picture download request, switchs to that the more primary code progress picture download of Thread Count can be opened, so as to improve picture download
Efficiency, and then client is improved to the efficiency of user's exhibiting pictures.
Further, according to the method shown in Fig. 1, an alternative embodiment of the invention additionally provides a kind of client downloads
The method of picture, as shown in Fig. 2 methods described mainly includes:
201st, when the browser that client is embedded sends picture download request to server, using belonging to the client
The primary code of operating system intercepts and captures the picture download request.
The specific implementation of this step is consistent with the specific implementation of step 101 in Fig. 1, will not be repeated here.
202nd, the primary code judges locally whether be cached with the corresponding image data of the picture download request;If institute
Stating the local cache of primary code has the corresponding image data of the picture download request, then performs step 203;If described primary
The local of code does not cache the corresponding image data of the picture download request, then performs step 204-206.
When user accesses same webpage again every time, client is required for from server side re-downloads webpage
Picture, still, in actual applications, user often frequently accesses same webpage, and (such as user browses 1 webpage half a day
1), therefore in order to improve the efficiency that user accesses Web page picture, certain image data is obtained from server side first in primary code
Afterwards, first the network address of the image data and picture can be cached to locally, then when user accesses the picture again, without
Picture down operation is carried out from server side again, directly image data is obtained from local.
Therefore, after primary code receives the picture download request that browser is sent to server, it can first judge local
Whether the picture download request corresponding image data is cached with;If local cache has the corresponding picture number of the picture download request
According to then the image data of local cache being sent into browser and be shown;If local be not cached with picture download
Corresponding image data is asked, then picture download request is sent to server again, from server side download pictures data.Its
In, primary code judges that the local specific implementation for whether being cached with the corresponding image data of picture download request can be with
For:Primary code first obtains the network address of picture from picture download request, then from the network address for locally searching the picture;If searching
To the network address of the picture, then the corresponding image data of the network address of the picture of local cache is defined as the picture download request pair
The image data answered;If not finding the network address of the picture, it is determined that the local not corresponding picture number of the picture download request
According to.
203rd, the image data of local cache is sent to the browser and shown by the primary code.
Because primary code is when image data is cached, the picture number that can be directly displayed can be directly cached
According to the image data that can not be directly displayed after the processing such as compression, encapsulation can also be cached, so primary code is by local cache
Image data be sent to the specific implementation that browser shown and can also be divided into two kinds:(1) primary code directly will
The image data of local cache is sent to browser, and browser is received after image data, however, it is determined that image data can not be direct
It has been shown that, then be first converted into the image data that can directly display, then shown by the image data;(2) if local cache
Image data can be directly displayed, then the image data is directly sent to browser and shown by primary code;If local slow
The image data deposited can not be directly displayed, then primary code first open that the image data of the caching is converted into by a thread can
The image data directly displayed, then the image data for being possible to directly display are sent to server and shown.
204th, the primary code opens at least one new thread and the picture download request is sent into the server.
The specific implementation of this step is consistent with the specific implementation of step 102 in Fig. 1, will not be repeated here.
205th, the primary code receives the image data that the server is returned.
During for the ease of subsequently accessing the image data again, picture display efficiency is improved, primary code reception can be worked as
After the image data returned to server, primary code can be cached image data, so as to follow-up directly from local
Obtain.
Specifically, primary code can be based on preset buffer memory mechanism, the image data that server is returned and corresponding
Network address is directly cached to locally;The picture number that can directly display can also be being got based on the image data that server is returned
According to rear, then the image data that directly displays is possible to based on the preset buffer memory mechanism and network address is cached to locally.
Wherein, preset buffer memory mechanism can include:Periodically delete the image data infrequently accessed and corresponding network address;
When client low memory, the longer image data of cache-time and corresponding network address are deleted;Only cache user is frequently visited
The image data asked and corresponding network address etc..
206th, the image data is sent to the browser and shown by the primary code.
The specific implementation of this step is consistent with the specific implementation of step 104 in Fig. 1, will not be repeated here.
The method of client downloads picture provided in an embodiment of the present invention, can not only be intercepted and captured under picture by primary code
Request is carried, is switched to by the less embedded browser download pictures of Thread Count can be opened by more primary of Thread Count can be opened
Code download pictures, so as to improve picture download efficiency, and then improve efficiency of the client to user's exhibiting pictures, can also be
The image data of download is cached to locally by primary code after server side download pictures based on caching mechanism, so that subsequently
, can be directly from corresponding image data be locally obtained, without spending time, wave when needing the client to show the picture again
Take flow from server side download pictures data, so as to further increase client to the efficiency of user's exhibiting pictures.
Referred in above-described embodiment, can be using the method download pictures downloaded on demand in order to save picture downloading flow.
As shown in figure 3, the solution of the present invention is introduced by taking the scene of download pictures on demand as an example below:
301st, after web data is obtained, the primary code of the affiliated operating system of client is by picture in the web data
Network address remove to default memory space.
Img labels in web data (such as html data) are used for an embedded width picture into webpage.And technically,
Img labels can't in webpage insert pictures substantive content, but the network address of insert pictures.Specifically, img labels contain
Two indispensable attributes, respectively src attributes and alt attributes.Wherein, src attributes are used for the network address of recordable picture, and alt attributes are used
In when picture can not be rendered, by only showing that pure words are used as a kind of remedial measure.If it follows that primary code is by net
The src attributes of img labels are removed to default memory space in network data, then browser can be caused can not to render corresponding picture,
So as to play prevention browser simultaneously by the locally downloading effect of all pictures in webpage.
Wherein, when src attributes are removed to default memory space, primary code can be only by " src=URL "
URL is removed, and URL can also be changed into other words, can also remove whole " src=URL ".In addition, default memory space
Can be the memory space where Custom Attributes data-src, you can so that the URL in src attributes is removed to Custom Attributes
In data-src.
302nd, the web data removed after network address is sent to the browser and shown by the primary code.
Wherein, the web data removed after network address is sent to after browser by primary code, and browser first can will remove picture
Other data in addition are rendered, during to other data renders, if finding to have the picture not loaded in screen,
The loaded and displayed of the picture can be realized by performing step 303-310.
303rd, when it is determined that there is the picture not loaded in screen, the primary code will be deposited in the default memory space
The network address of the picture not loaded of storage is added to the correspondence position of the web data.
Wherein, primary code judges whether the specific implementation containing the picture not loaded can be in screen:Pass through
JavaScript method judges whether img labels enter the screen;If into the screen, judging the img labels pair
Whether the picture answered is downloaded, if not being downloaded, it is determined that there is the picture that does not load in the screen, if into screen
The corresponding picture of img labels is all downloaded, it is determined that the picture not loaded is not present in the screen;If no img labels enter
Enter the screen, it is determined that the picture not loaded is not present in the screen.Wherein, JavaScript method is to be based on primary language
Say one section program of the execution write in embedded browser.
When it is determined that there is the picture not loaded in screen, primary code can determine that browser has the need for rendering picture
Ask, therefore the src attributes of the corresponding img labels of the picture not loaded stored in default memory space can be added to this
Img labels, picture download request is sent to trigger browser by the URL in src attributes to server.
304th, the browser sends the picture download request for carrying the network address to the server.
305th, the picture download request is intercepted and captured using the primary code of the affiliated operating system of the client.
306th, the primary code judges locally whether be cached with the corresponding image data of the picture download request;If institute
Stating the local cache of primary code has the corresponding image data of the picture download request, then performs step 307;If described primary
The local of code does not cache the corresponding image data of the picture download request, then performs step 308-310.
307th, the image data of local cache is sent to the browser and shown by the primary code.
308th, the primary code opens at least one new thread and the picture download request is sent into the server.
309th, the primary code receives the image data that the server is returned.
310th, the image data is sent to the browser and shown by the primary code.
Further, according to above method embodiment, an alternative embodiment of the invention is additionally provided under a kind of client
The device of picture is carried, as shown in figure 4, described device mainly includes:Intercept and capture unit 41, transmitting element 42, receiving unit 43.Its
In,
Unit 41 is intercepted and captured, for when the browser that client is embedded sends picture download request to server, using institute
The primary code for stating the affiliated operating system of client intercepts and captures the picture download request;
Transmitting element 42, intercepts and captures the intercepting and capturing unit 41 for opening at least one new thread by the primary code
The picture download request be sent to the server;
Receiving unit 43, for receiving the image data that the server is returned by the primary code;
The transmitting element 42, which is additionally operable to the image data is sent into the browser by the primary code, to be entered
Row display.
Optionally, as shown in figure 5, described device also includes:
Judging unit 44, for opening at least one new thread by institute by the primary code in the transmitting element 42
State picture download request to be sent to before the server, judge locally whether be cached with the picture by the primary code
The corresponding image data of download request;
The transmitting element 42 is used for when the judged result of the judging unit 44 does not have for the local of the primary code
When caching the corresponding image data of the picture download request, pass through the primary code open at least one described new thread will
The picture download request is sent to the server.
Optionally, the transmitting element 42 is additionally operable to when the judged result of the judging unit 44 is the primary code
When local cache has the picture download request corresponding image data, by the primary code by the picture number of local cache
Shown according to the browser is sent to.
Optionally, as shown in figure 5, described device also includes:
Buffer unit 45, for being based on preset buffer memory mechanism, the figure that the server is returned by the primary code
Sheet data and corresponding network address are cached to locally;Or, by the primary code in the figure returned based on the server
Sheet data is got after the image data that can be directly displayed, and can be directly displayed described based on the preset buffer memory mechanism
Image data and the network address are cached to locally.
Optionally, as shown in figure 5, described device also includes:
Converting unit 46, for the image data to be sent into institute by the primary code in the transmitting element 42
State before browser shown, if the image data can not be directly displayed, by the primary code open independently of
The figure that the image data that the server is returned is converted into directly displaying by other threads of at least one new thread
Sheet data;
The transmitting element 42 is additionally operable to send the image data that can be directly displayed by the primary code
Shown to the browser.
Optionally, the browser that the transmitting element 42 is additionally operable to embed by client sends picture download to server
Request;
As shown in figure 5, described device also includes:
Unit 47 is removed, for sending picture to server by the embedded browser of client in the transmitting element 42
Before download request, after web data is obtained, the network address of picture in the web data is removed by the primary code
To default memory space;
The transmitting element 42 is additionally operable to be sent to the web data removed after network address by the primary code described
Browser is shown;
Adding device 48, for when it is determined that there is the picture not loaded in screen, by the primary code by described in
The network address of the picture not loaded stored in default memory space is added to the correspondence position of the web data;
The transmitting element 42 is used to send to the server under the picture for carrying the network address by the browser
Carry request.
The device of client downloads picture provided in an embodiment of the present invention, the browser that can be embedded in client is to service
When device sends picture download request, first using the primary code for the affiliated operating system of client that can open more multithreading simultaneously
The picture download request is intercepted and captured, then by primary code according to default download mechanism, opening at least one new thread should
Picture download request is sent to server, (for example, when the picture download request of intercepting and capturing is more, can open multiple new threads
These picture download requests are concomitantly sent to server), last primary code receives the image data of server return
Afterwards, the image data can be sent into the embedded browser by primary code to be shown.It follows that and prior art
In directly compared by the less embedded browser download pictures of Thread Count can be opened, the present invention by intercept and capture browser send
Picture download request, switchs to that the more primary code progress picture download of Thread Count can be opened, so as to improve picture download
Efficiency, and then client is improved to the efficiency of user's exhibiting pictures.In addition, in primary code from server side download pictures
Afterwards, the image data of download is cached to locally based on caching mechanism, so that when subsequently needing the client to show the picture again,
Can be directly from corresponding image data be locally obtained, without spending the time, wasting flow from server side download pictures number
According to so as to further increase client to the efficiency of user's exhibiting pictures.
In the above-described embodiments, the description to each embodiment all emphasizes particularly on different fields, and does not have the portion being described in detail in some embodiment
Point, it may refer to the associated description of other embodiment.
It is understood that the correlated characteristic in the above method and device can be referred to mutually.In addition, in above-described embodiment
" first ", " second " etc. be to be used to distinguish each embodiment, and do not represent the quality of each embodiment.
It is apparent to those skilled in the art that, for convenience and simplicity of description, the system of foregoing description,
The specific work process of device and unit, may be referred to the corresponding process in preceding method embodiment, will not be repeated here.
Algorithm and display be not inherently related to any certain computer, virtual system or miscellaneous equipment provided herein.
Various general-purpose systems can also be used together with based on teaching in this.As described above, construct required by this kind of system
Structure be obvious.In addition, the present invention is not also directed to any certain programmed language.It is understood that, it is possible to use it is various
Programming language realizes the content of invention described herein, and the description done above to language-specific is to disclose this hair
Bright preferred forms.
In the specification that this place is provided, numerous specific details are set forth.It is to be appreciated, however, that the implementation of the present invention
Example can be put into practice in the case of these no details.In some instances, known method, structure is not been shown in detail
And technology, so as not to obscure the understanding of this description.
Similarly, it will be appreciated that in order to simplify the disclosure and help to understand one or more of each inventive aspect, exist
Above in the description of the exemplary embodiment of the present invention, each feature of the invention is grouped together into single implementation sometimes
In example, figure or descriptions thereof.However, the method for the disclosure should be construed to reflect following intention:It is i.e. required to protect
The application claims of shield features more more than the feature being expressly recited in each claim.More precisely, such as following
Claims reflect as, inventive aspect is all features less than single embodiment disclosed above.Therefore,
Thus the claims for following embodiment are expressly incorporated in the embodiment, wherein each claim is in itself
All as the separate embodiments of the present invention.
Those skilled in the art, which are appreciated that, to be carried out adaptively to the module in the equipment in embodiment
Change and they are arranged in one or more equipment different from the embodiment.Can be the module or list in embodiment
Member or component be combined into a module or unit or component, and can be divided into addition multiple submodule or subelement or
Sub-component.In addition at least some in such feature and/or process or unit exclude each other, it can use any
Combination is disclosed to all features disclosed in this specification (including adjoint claim, summary and accompanying drawing) and so to appoint
Where all processes or unit of method or equipment are combined.Unless expressly stated otherwise, this specification (including adjoint power
Profit is required, summary and accompanying drawing) disclosed in each feature can or similar purpose identical, equivalent by offer alternative features come generation
Replace.
Although in addition, it will be appreciated by those of skill in the art that some embodiments described herein include other embodiments
In included some features rather than further feature, but the combination of the feature of be the same as Example does not mean in of the invention
Within the scope of and form different embodiments.For example, in the following claims, times of embodiment claimed
One of meaning mode can be used in any combination.
The present invention all parts embodiment can be realized with hardware, or with one or more processor run
Software module realize, or realized with combinations thereof.It will be understood by those of skill in the art that can use in practice
Microprocessor or digital signal processor (DSP) come realize client downloads picture according to embodiments of the present invention method and
The some or all functions of some or all parts in device.The present invention is also implemented as being used to perform being retouched here
The some or all equipment or program of device (for example, computer program and computer program product) for the method stated.
Such program for realizing the present invention can be stored on a computer-readable medium, or can have one or more signal
Form.Such signal can be downloaded from internet website and obtained, either on carrier signal provide or with it is any its
He provides form.
It should be noted that the present invention will be described rather than limits the invention for above-described embodiment, and ability
Field technique personnel can design alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference symbol between bracket should not be configured to limitations on claims.Word "comprising" is not excluded the presence of not
Element or step listed in the claims.Word "a" or "an" before element does not exclude the presence of multiple such
Element.The present invention can be by means of including the hardware of some different elements and coming real by means of properly programmed computer
It is existing.In if the unit claim of equipment for drying is listed, several in these devices can be by same hardware branch
To embody.The use of word first, second, and third does not indicate that any order.These words can be explained and run after fame
Claim.