Is there anyway to leverage browser caching via ColdFusion or does it have to be done at server level (IIS)?
I'm looking to cache images, CSS and JS files.
I have seen Leverage browser caching - if it's not possible in CF, how do I go about adding images/CSS/JS files to that solution?
Thanks,
JJ
CF, normally, isn't serving images, CSS and JS files. You would want to do this via your web server instead. For the files that CF does serve, you can use cfheader to return an expires values in the future. See the core docs on cfheader for an example.
Related
I am looking into possibly setting up a CDN to use with my Wagtail sites. I am thinking that this will be a more efficient way to manage media uploads during stage/production pushes, since right now the media folder has to be manually copied from server to server on deploy. If all of the images were being accessed from a CDN then this wouldn't be an issue.
This would be my first time using a CDN so I'm looking for advice. There is lots of info on using a CDN with WordPress, but not a lot of documentation on setting one up with Wagtail/Django. I have the following questions about it:
Does anyone have any suggestions on the best way to implement the CDN with Wagtail?
How does it handle the uploads that the user submits through the CMS? Most of the images will be uploaded as part of the static files, but how does it work when the user uploads a photo as part of a post?
Which CDN companies have you had the best/worst experiences with? The sites I am planning to use this for are professional/business, but not e-commerce.
Also, if there is a more efficient way to handle the transfer of media uploads from one environment to another than using a CDN, I'd love to hear your suggestions for that too. As of right now I've had to copy the media folder over after doing the deploy, and I will have to do this every time I make a change to the site.
Thanks in advance for your assistance.
The following resources can be helpful for your required setup in Wagtail (later on today I can provide you some more details):
Frontend cache invalidator for pages (so not only for static and media files)
Link: http://docs.wagtail.io/en/latest/reference/contrib/frontendcache.html#frontendcache-aws-cloudfront
Storing media files in Amazon Web Services S3 buckets
This should be a better solution instead of copying media files from server to server. In this case Amazon Web Services CloudFront (CDN) would be a perfect choice.
Link: https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#amazon-s3
More info CloudFront: https://aws.amazon.com/cloudfront/
Static file cache invalidation with Django Whitenoise
Can be relevant to clear the cache for a new deployment (the static files will have a unique filename so CDN will have a new file cache from its origin after the deployment)
Link: http://whitenoise.evans.io/en/stable/django.html
CloudFront from AWS will have my personal choice for CDN. Besides the awesome resources/services AWS has to offer, CloudFront is simple to setup and has one of the best CDN's out there.
Finally a CDN for serving static- and media files has nothing to do with Wagtail specifically. There are some (see list above) nice apps available for Django itself, but you are free to choose another CDN solution (like Cloudflare).
So setting up a AWS S3 Bucket for each environment (tst/acc/stg/prd) and use it for uploading you media files (so the files aren't on the server anymore) and setup a CloudFront distribution for these buckets would be a proper solution for your problem.
Best regards,
Rob Moorman
I want to enable browser caching of images, css and java script files.
https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers
The heroku article says this in its conclusion:
"Once the concepts behind HTTP caching are understood the next step is to implement them in your application. Most modern web frameworks make this a trivial task."
Can someone tell me how to do this trivial task? I have a django-python app.
Your static resources should really be served from a webserver such as nginx or apache and not directly from django but to answer your question, django inlcudes a staticfiles app which one assumes you are using to manage those resources, if so, use
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
in your settings.py file to enable django's caching for staticfiles.
c.f
https://docs.djangoproject.com/en/1.6/ref/contrib/staticfiles/#cachedstaticfilesstorage
https://docs.djangoproject.com/en/1.7/ref/contrib/staticfiles/#cachedstaticfilesstorage
[the 1.6 link has more explanation of how this works]
For caching as a whole in django, I recommend reading https://docs.djangoproject.com/en/1.7/topics/cache/
where you can see how to use middleware for site level caching or the cache_control decorator for view-caching like so:
from django.views.decorators.cache import cache_control
#cache_control(must_revalidate=True, max_age=3600)
def my_view(request):
# ...
The static files like images, css and javascript should be served directly by the webserver (e.g. Apache of nginx), not by Django. Therefore you should configure any caching in your web server configuration, not Django.
If you are hosting your Django project on Heroku, they appear to recommend whitenoise according to this article.
I'm working on several Django projects on my local machine, following a single page application architecture. To initiate the server, I have a couple copies of a script in my /bin folder containing
#!/bin/bash
python /path/to/app/manage.py runserver 8080
and have each script with the app name. This makes the application accessible via localhost:8080. In addition, I usually have the majority of my site CSS inside main.css
My issue is that I seem to be coming across a caching issue with Firefox, regardless of which application server is running. Sometimes a page will load with almost no CSS styling, but the jQuery UI elements will be initialized and I can interact somewhat with the application, although the functionality and styling is seriously broken. Refreshing the page shows no improvement, and no errors are shown in the console.
Clearing the cache and changing the port in the scrip seem to solve the issue, but it requires me to have bookmarks for each project, whereas it is pretty convenient to have a single localhost:8080 URL for all projects.
Has anyone come across this issue, and is there a solution other than clearing cache and changing ports?
This thread discusses methods to prevent client side caching of content served by the development server in Django:
Fighting client-side caching in Django
I prefer to simply disable caching in my browser though, seeing that I spend so much time on developing that I don't want to bother with the hassle of trying to prevent it in my own code.
A simple web search for "how to disable caching in firefox" came up with this:
http://support.mozilla.org/en-US/questions/764993
I'm pretty sure that searching for the same thing for different browsers will also give you expected results.
EDIT:
These guys also seem to go pretty in depth about how to prevent the caching of static files when using the Django development server.
Turn off caching of static files in Django development server
Just add something like this to /etc/hosts:
127.0.0.1 site1.dev
127.0.0.1 site2.dev
Visit site1.dev:8080, now site1 has its own cache and cookies (session) in the browser.
I am designing an iphone forum application with django running in amazon ec2. Currently I am learning to deploy django using either nginx or apache. I am confused about media server and normal server. A lot of sources say that nginx is good for serving media files or static content, what does that mean? For normal group conversation/forum application, how does apache and nginx differ in performance etc? When is my mobile application serving dynamic content and when is it serving static content?
Googling will find you better results for a comparison between Apache vs Nginx than anyone on this site can give you. It is too broad of a question and can be highly subjective.
Media Files
Media in a django context generally refers to files that have been uploaded by end users. It is common to have a django view that initially uploads the users file, but then any future access to it is served by a traditional web server like nginx.See the docs for more info.
Static Files
Static in a django context refer to images, javascript and css files. While developing your site, the built-in django development server will serve these files for you. However, when moving to production you will want to use a traditional web server like apache to serve these files. See the docs for more details.
Dynamic Content
This would refer to the content (html, json, xml etc.) that is generated by the views that you write within Django.
I am looking at the following demo - http://blueimp.github.com/jQuery-File-Upload/
To my understanding in the demo, php files are being served from github which means php content can be served / run from github.
I understand the process to publish html content from code hosted at github via this link - http://help.github.com/pages/ I am just curious to know how can I show a .php page as a demo, similar to what is done in blueimp above.
I tried similar thing at http://synechron.github.com/index2.php but instead of displaying in the browser window the page gets downloaded in Google chrome and in IE9 index.html is displayed.
Github Pages is not a full-featured web host. It will not execute PHP, or any other arbitrary code.
No, you can’t.
Github Pages let you serve web client content (HTML, Javascript, CSS) without the need of owning and maintaining a web server. You can make sub folders, map your domain into it. Use tools such as Jekyll or Hugo with some basic programming skills, you can make your site work as good as an CMS.
However, it does not allow you to use any backend technology to process and manipulate data/logic.
So, PHP is not possible.