• Wordpress creating cache of search results in the browser

    When you search for a term in wordpress, it creates a url for that term.

    For example, if you search for searchtest it will return a url:
    example.com/?s=searchtest

    If you make a new post and run the search again. the result will not include this last post.

    In order to view, you will need to do one of the two things below:
    01 Reload the Browser.
    02 Wait for the cache expiration defined in htaccess.

    We have a problem there.
    If we reduce the cache time in htaccess it will affect the entire site.

    The search results will be accurate, but the site will make many unnecessary requests in addition to slowing down all navigation.

    That’s where the point comes.
    How to disable the cache ONLY on links created by search results?

    So the results would always be up to date but without compromising performance.

    I try this, but doesnt work:

    <LocationMatch ".*/\?s=.*"> 
      Header Set Pragma "no-cache"
      Header Set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
      Header Set Cache-Control "max-age=0, no-store, no-cache, must-revalidate"
      Header Unset ETag
      FileETag None
    </LocationMatch>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    what plugin are you using for caching?

    Thread Starter delaitec

    (@delaitec)

    In my tests, I found that adding a new version to the end of the url generated in each search

    & v1
    & v2
    & v4

    etc., the search page will not use the browser cache and will always return a real result with the latest posts.

    Is it possible to add a code at the end of the search url that changes with each new search? it can be a timestamp for example.

    Can this be done by the funcions file? or would it be via htaccess?

    Thread Starter delaitec

    (@delaitec)

    Hello Steven.
    I’m not using any plugins.

    I am currently trying to resolve this issue.

    I need a way in which searches return the actual result, and wordpress is not doing this.

    You can reproduce it as follows
    01 – Post something with a unique name, for example: “aabbcc 01”.
    02 – Do a search. It will be displayed in the results.
    03 – Go back to your home page.
    04 – Change the file name to “aabbcc 02” and save.
    05 – Do a search, the “aabbcc 01” will still be displayed
    06 – Update the page with the search result, “aabbcc 02” will be displayed.

    That is, if you search for the same term, the results will not be true until the cache time expires, or if you click refresh.

    We cannot expect the user to deduce that he will need to refresh the page after his search to have a real result.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress creating cache of search results in the browser’ is closed to new replies.