Git Product home page Git Product logo

quicksilver's Introduction

REPOSITORY MOVED TO GITLAB https://gitlab.biz-mark.ru/free-plugins/Quicksilver

OctoberCMS lightning fast static files cache system

Quicksilver in OctoberCMS Marketplace

This is adaptation of package: JosephSilber/page-cache (Go get him some stars)

Lightning fast cache system that converts your website page to static html files. Super useful for anyone who wants their static website to be faster.

Work in progress.

Notes

THIS CACHE SYSTEM ONLY SUITABLE FOR BASIC WEBSITES. BECAUSE OF STATIC FILES, YOU MAY SEE CHANGES ON WEBSITE ONLY AFTER CLEARING CACHE.

Work still in progress.

This plugin caches every route that opens by GET parameter with 200 response code. Except for every url that is matching your 'backendUri' defined in config/cms.php.

Installation

Open Settings in the control panel of your OctoberCMS website. Go to Updates & Plugins and in search bar type "Quicksilver". Install it by clicking on the icon.

Configuration

Apache

  1. Open .htaccess and add the following before Standard routes section

    ##
    ## Serve Cached Page If Available
    ##
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/storage/page-cache/pc__index__pc.html -f
    RewriteRule .? /storage/page-cache/pc__index__pc.html [L]
    RewriteCond %{DOCUMENT_ROOT}/storage/page-cache%{REQUEST_URI}.html -f
    RewriteRule . /storage/page-cache%{REQUEST_URI}.html [L]
    RewriteCond %{HTTP:X-Requested-With} XMLHttpRequest
    RewriteRule !^index.php index.php [L,NC]
    
  2. Comment out following line in White listed folders section.

    RewriteRule !^index.php index.php [L,NC]
    
  3. Be sure that plugin can create/write/read "page-cache" folder in your storage path.

Nginx

location = / {
    try_files /storage/page-cache/pc__index__pc.html /index.php?$query_string;
}

location / {
    try_files $uri $uri/ /storage/page-cache/$uri.html /storage/page-cache/$uri.json /index.php?$query_string;
}

If you need to send ajax requests to cached url, you should use this construction

location / {
    if ($request_method = POST ) {
        rewrite ^/.*$ /index.php last;
    }

    try_files $uri $uri/ /storage/page-cache/$uri.html /storage/page-cache/$uri.json /index.php?$query_string;
}

Ignoring the cached files

To make sure you don't commit your locally cached files to your git repository, add this line to your .gitignore file:

/storage/page-cache

Clearing the cache

Since the responses are cached to disk as static files, any updates to those pages in your app will not be reflected on your site. To update pages on your site, you should clear the cache with the following command:

php artisan page-cache:clear

As a rule of thumb, it's good practice to add this to your deployment script. That way, whenever you push an update to your site the page cache will automatically be cleared.

If you're using Forge's Quick Deploy feature, you should add this line to the end of your Deploy Script. This'll ensure that the cache is cleared whenever you push an update to your site.

You may optionally pass a URL slug to the command, to only delete the cache for a specific page:

php artisan page-cache:clear {slug}

Customizing what to cache

By default, all GET requests with a 200 HTTP response code are cached. If you want to change that, create your own middleware that extends the package's base middleware, and override the shouldCache method with your own logic.

Example:

<?php namespace Acme\Plugin\Middleware;

use Request;
use Response;

use BizMark\Quicksilver\Classes\Middleware\CacheResponse as BaseCacheResponse;

class CacheResponse extends BaseCacheResponse
{
    protected function shouldCache(Request $request, Response $response)
    {
        // In this example, we don't ever want to cache pages if the
        // URL contains a query string. So we first check for it,
        // then defer back up to the parent's default checks.
        if ($request->getQueryString()) {
            return false;
        }

        return parent::shouldCache($request, $response);
    }
}

Update the Plugin.php of BizMark\Quicksilver and pass your new CacheResponse class to pushMiddleware() method.

Don't forget to freeze all updates of Quicksilver plugin at settings of your OctoberCMS website. Otherwise all your changes in Plugin.php file will be overwritten by next update from marketplace.


© 2019, Biz-Mark under the MIT license.

Adaptation for OctoberCMS by Nick Khaetsky at Biz-Mark.

quicksilver's People

Contributors

blakej115 avatar flusherdock1 avatar lemax10 avatar publialex avatar tarasmykytka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

quicksilver's Issues

Fatal error after backend logout

Hello,

After installing this module, on a fresh install. When you logout the backend, you have an error :

Type error: Argument 2 passed to BizMark\Quicksilver\Classes\Middleware\CacheResponse::shouldCache() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\RedirectResponse given, called in /plugins/bizmark/quicksilver/classes/middleware/CacheResponse.php on line 43

Quite critical here as you can't login anymore without commenting the if statement in line 43-45 in CacheResponse.php

Query String Support

Hello!

I love this plugin (I left a nice review on the marketplace)

I wondered if you have considered adding logic to support query strings?

I understand that the current aim for the plugin is to speed up fairly static sites, which this does brilliantly, but I feel that API driven sites would benefit here, too.

This is something I need, but obviously it's quite a demand as it deviates from the intention of the base package. I will fork and work on this for my own needs, but I would like to hear your thoughts on whether its something you'd be interested in merging in the future.

Cheers!

Generate Static HTML for anonymous users only

Hello,

I noticed something really annoying with this module.

It actually cache static HTML file as it's viewed. This means it will cache and serv to everybody all administrative tools you can have on your frontend as a website administrator.

Here is a small example : Let's imagine you use the excellent content editor plugin to manage your frontend texts. The page will be cached including that small blue pen on the top left corner of each pages. Once cached, even anonymous visitors will see this pen, and they will see all others tools of special classes an administrator could have on a website frontend. This can lead to big UI and security issues.

There are 2 things to do to correct that problem :

  • Be sure that, when you cache the page, you cache only anonymous version of pages (anonymous from backend, but also from users logged with the user plugin)

  • Serve cached page only for anonymous (people logged as backend admin, or frontend user should not see cached version)

This is what most (to not say all) cms I know do, cached pages are only made for anonymous users, to speedup page load. Once they are connected, pages are dynamically calculated.

Best regards,

Alex

Dashboard widget to clear cache

Hello,

Really nice to see some performance boost plugin for october CMS. I developped many sites with it, performances are OK but I could never decrease the TTFB below 800ms, which is quite high, even for small websites.

Hope to go below 500ms using static cache...

However, I have a feature request : The clients for which I develop websites are not developers and can't type artisan command to clear cache. It would be a great addition to be able to do that in a widget directly in the October CMS dashboard.

Do you think it could be possible ?

Best regards,

Alex

Add an exception

Is it possible to add an exception in the CacheResponse file for: rss.xml, sitemap.xml or {{blog.views}}!?

Encoding issue for cached pages

Hello,

Congratulation for your plugin, I could notice very big performance improvements, especially concerning TTFB.

However, I noticed a bug with character encoding. All accents are displayed weirdly, for example, the word : "réception" is displayed "réceptions".

It's probably related to page encoding, I suggest you use UTF-8 for better support of special characters.

Best regards,

Alex

2.0 issues

Hello,
Since 2.0 update. Plugin stopped to work correctly. Pages are created in /page-cache but only homepage seems to load from there. Can you post your whole clean October .htaccess, properly modified for v2.0? I guess maybe there is a problem. And I don't speak Russian to follow forum.

Thanks!

sitemap.xml

Hello Community, it's a super plugin! But it also caches sitemap.xml.
Please help me and advise, how to exclude sitemap.xml from caching.
Thank you very much in advance
Kind Regards Igor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.