I have a django application and I would like to enable cloudflare to speedup the web response.So I would like to know how much cloudflare can caches my application?
In the application most of the pages are dynamic and eachone atleast contain the loggedin user name.Is there any other way cloudflare handle highly cacheable websites
CloudFlare's CDN caches the following types of static content by extension for all account types by default:
css,bmp,tif,ttf,docx,js,pict,tiff,eot,xlsx,jpg,csv,eps,woff,xls,jpeg,doc,ejs,otf,pptx,gif,pdf,swf,svg,ps,ico,pls,midi,svgz,class,png,ppt,mid,webp,jar
From this page, it is said that:
If you are looking for more advanced caching or performance options,
please look at our paid plans that can help extend caching and
performance for your site.
Also, the about Cloudflare's caching mechanism, its explained in this page:
To speed up the response time for a request that goes to a one of our
frontline servers, CloudFlare caches parts of websites that are static
in these servers. For example, we cache things like images, CSS, and
JavaScript. We are very conservative with our caching because we never
want to mess up dynamic content. So, for example, as a general rule we
do not cache HTML. We also refresh the cache relatively frequently, so
files are never more than a few hours old. Even being conservative,
however, typically 50% of the resources on any given web page are
cacheable.
And about the point about eachone atleast contain the loggedin user name.. Its related to django backend. I have used a django powered site with cloudflare, had no problem with logged in users.
You can check this library for caching: https://github.com/koalalorenzo/django-smartcc
Try a page rule like this as your last one:
example.com/
There should be an asterisk at the beginning and end of this rule
Choose "cache everything." This will cache html.
Test results on your dynamic content caching.
Related
I have a website developed using Flask framework.
I want to cache all my pages to make my website faster and increase traffic on search engines.
However, the page has user-specific dynamic content.
I would really appreciate it if you could tell me how to cache dynamic content.
User-specific dynamic content is only good for one user, so caching it is not useful, and Cloudflare doesn't cache it by default. If you force it to, it will break your site, because users will get content intended for other users.
Cloudflare will, however, cache your images, CSS, Javascript, and so forth.
I solved this dynamic content caching problem using ajax requests for user-specific data.
After loading static content, I requested user-specific data such as current user information via ajax.
I set cache option to false when making ajax request.
In this way, I can solve the dynamic content caching problem.
The static page content comes from Django CMS which makes it dynamic , How is using nginx in such a scenario beneficial ?
It is generally considered a best practice to have "static" content served by a traditional web server such as Nginx or Apache. By static content, I am referring to things like CSS, JavaScript, and Images. Since these files often don't require modification between requests, there is little sense in having Django serve them. And Nginx/Apache can be serving these files to the client's browser concurrently.
However, your dynamic content served by Django needs to be rendered within the context of one or more Django templates. Not to mention, content such as blog posts needs to be retrieved from the database. Fortunately, Django has a robust caching system that you can use to cache the rendered HTML output and decrease server load and response times.
How much of a performance boost you gain really depends on the situation. I can tell you from experience that caching a complex response has reduced the response time from 300ms down to 30ms in one scenario.
EDIT: Adding a great article on Scaling Django: Caching and Static Content.
My UI designer is making me a rich html and java script front-end which is supposed to work with my Django server. I have provided him a bunch of APIs to get different elements from the server. (i.e. an api to load the images, another api to load some text, another api to load bigger size image when somebody clicked on a small one, etc.) The problem with this is that every time a user visits the page, I will be getting some number of requests.
On the other hand, I could have used django template tagging to render the page once with all the elements needed. however,
I was wondering if there is a clear benefit in one of these options?
As #limelights said, try not to optimise too early. Because you don't really know what will be your bottleneck.
And when you'll have problems, the first thing to check is your queries to the database. Do you use selectect_related() and are your indexes optimal for your requests. This include the queries that javascript make via django (Try to load all the child node needed in one or two requests, as select_related() do).
After that the next optimisation should probably be cache. Here's the doc about the django's cache framwork.
After that there's adanced optimisation with database denormalization, apache or nginx optimisation, mysql or postgresql settings optimisation, load balancing and etc... Those optimizationg should be done because you have a problem of popularity, not just for a few users.
I have a handful of users on a server. After updating the site, they don't see the new pages. Is there a way to globally force their browsers and providers to display the new page? Maybe from settings.py? I see there are decorators that look like they do this on a function level.
Depends on browser and cache settings.
There may be no way to tell browsers to do so (as pages are cached, they are not even talking to server, so there is nothing You can do there).
Good trick is to set Vary: Cookie header, so You can always invalidate cache (by changing cookie somewhere) in case of need.
One way to force the browser to load a new page rather than loading the cached version is to change the file name. You could add a date/time to the file name and use a rewrite rule (assuming Apache web server here) to get the new page.
This site gives a quick explanation: http://www.askapache.com/htaccess/mod_rewrite-fix-for-caching-updated-files.html
and google will show many more.
you may also have to examine your cache control headers.
I'm looking at setting up a small company that hosts flash-based websites for artist portfolios. The customer control panel would be django-powered, and would provide the interface for uploading their images, managing galleries, selling prints, etc.
Seeing as the majority of traffic to the hosted sites would end up at their top level domain, this would result in only static media hits (the HTML page with the embedded flash movie), I could set up lighttpd or nginx to handle those requests, and pass the django stuff back to apache/mod_whatever.
Seems as if I could set this all up on one box, with the django sites framework keeping each site's admin separate.
I'm not much of a server admin. Are there any gotchas I'm not seeing?
Maybe. I don't think the built-in admin interface is really designed to corral admins into their own sites. The sites framework is more suited to publish the same content on multiple sites, not to constrain users to one site or another. You'd be better off writing your own admin interface that enforces those separations.
As far as serving content goes, it seems like you could serve up a common (static) Flash file that uses a dynamic XML file to fill in content. If you use Django to generate the XML, that would give you the dynamic content you need.
This django snippet might be what you need to keep them seperate:
http://www.djangosnippets.org/snippets/1054/
"A very simple multiple user blog model with an admin interface configured to only allow people to edit or delete entries that they have created themselves, unless they are a super user."
Depending on the amount of sites you're going to host it might be easier to write a single Django app once, with admin, and to create a separate Django project for each new site. This is simple, it works for sure AND as an added bonus you can add features to newer sites without running the risk of causing problems in older sites.
Then again, it might be handier to customize the admin such that you limit the amount of objects users can see to those on the given site itself. This is fairly easy to do, allthough you might want to use RequestSite instead of the usual Site from the sites framework as that requires separate settings for each site.
There exists this one method in the ModelAdmin which you can override to have manual control over the objects being edited.