»Technical toss»Use browser script to make real-time disaster recovery backup for WordPress background articles
Based on the technology of js, we can save the input records of the website editor in real time, and the cache of backup records can prevent the tragedy caused by unsaving.
preface
I believe that many people have encountered the situation that when you write a great article and write it brilliantly, but you accidentally close the browser manually, or do not save it or the browser crashes unexpectedly, or the computer system suddenly gets stuck, resulting in the loss of the article. At this time, let you rewrite it again,Then you must feel like the sun is up.What Yunluo wants to solve today is this problem, because I also encountered this problem last night.
explain
Before discussing this issue, let's talk about the save function of WordPress.In fact, WordPress has its own automatic saving function, but its automatic saving is saved to the database of the remote server, and it is not saved in real time, it is saved regularly. In addition, when saving, it will have a certain network delay, which will cause some jams in the editor, and there will be a certain degree of jamming,At this time, you will find that your editing experience is very poor, and sometimes you have an impulse to give up writing.In addition, the automatic saving of WordPress will occupy the database space, so in order to reduce the database space, I have always disabled the automatic saving function here.
solve
In fact, the backup and recovery of data has always been a very important problem, which can be encountered in many cases. For example, the backup and recovery of our database, the backup and recovery of our articles are also important. In fact, we have a textarea cache plug-in on Firefox, which can save our records in real time,I have never found a similar plug-in, or there is a similar plug-in, but the function is very poor and the experience is very bad. So Yunluo wants to write a script again today to solve this problem. It is impossible to write a general script, but it is still possible to write a script specifically for WP.
Technical Principles
In fact, from a technical point of view, it is very simple to solve this problem. By looking at my script code, you can see that the code is very small, and in fact, it mainly uses several functions.One is the value and assignment of the text box, and the other is the write and read of the cache.The technical process is to save the content entered in the text box to the browser's cache in real time. When the browser crashes or closes, and the interface is reopened, click the Restore button to extract the content from the cache directly into the inserted text box. To solve the problem of cache volume, the function of automatically clearing the cache is added.When you click Save Draft, Publish Article, or Delete Article, the cache will be automatically cleared because the cache is no longer necessary.
Script Usage
After the script is installed, open it. On the background article creation or editing page, you will see a one button restore button next to the media button. Enter text in the text box, close the page, and then reopen it. Click the restore button to restore the previously entered content.
The above dynamic diagram needs to be viewed after clicking
Particular attention
One thing to note is that when you need to back up after closing the web page, you must first perform the backup and restore operation. Do not click the text box or enter text, or the newly entered text will overwrite the previous backup content. In addition, after clicking Restore, the script will automatically clear the cache.Therefore, there is only one chance to restore the article, not a second chance.