WebFaction
Community site: login faq

Hi there,

Firstly thanks for the great service so far, always a pleasure to work with webfaction.

I have a small problem; but also one vital for performant websites.

Files being served from my static app; are being served with a header 200; which is ok for the first load; however for the sake of speed and browser caching; loaded files should be header 304 Not Modified.

Have I missed something in the setup?

Thanks Ross

asked 30 May '12, 01:53

RossCdH
2612
accept rate: 100%


So.. the short answer is... you do indeed need to create a static service with the expires max setting

and if you are using jquery.. you must also have...

$.ajaxSetup({ cache: true });

and in your ajax calls

$.ajax({
            url: data.widgets[index],
            dataType: 'script',
            cache: true, // <------ NOTE THIS :)
            complete: function(xhr) { 
                if (xhr.status == 304) return;
            },
            error: function () {
                cartvine_is_ready = false;
            }
        });
permanent link

answered 30 May '12, 02:35

RossCdH
2612
accept rate: 100%

edited 30 May '12, 02:46

ryans ♦♦
5.0k103960

Thanks for sharing!

(30 May '12, 02:46) ryans ♦♦

Currently, the only header supported at this time by our Static-Only applications is the Expires Max header: http://docs.webfaction.com/software/static.html#setting-expires-max

Will this have a similar effect for your needs?

permanent link

answered 30 May '12, 02:01

ryans ♦♦
5.0k103960
accept rate: 43%

Hi @Ryans, ill give that a quick go and see if it meets.

Thanks for the quick response.

Ross

(30 May '12, 02:07) RossCdH

Sure. Be sure to actually delete and recreate the application rather than simply editing the Extra Info - the expires headers will only take effect if the static application is created with that value.

(30 May '12, 02:11) ryans ♦♦

Yeah I figured as much; I've created a whole new static app new name etc..

have hooked it up to the website as appropriate and (its a django site) manage.py collectstatic... all of which works well and the files are being served..

however the header is still 200... eeenteresting?

(30 May '12, 02:15) RossCdH

Hmm having said that.. it appears to return 304 correctly when accessing the app itself.. however when loading js from remote it still returns 200.. ill investigate this a bit deeper perhaps its simply the js load method im using :) but thanks for the tip :)

(30 May '12, 02:17) RossCdH

Seems to be a jquery .ajax and getScript issue. Might have to stackoverflow it...

$.each(data.widgets, function(index) {
    $.ajax({
        url: data.widgets[index],
        dataType: 'script',
        complete: function(xhr) { 
            console.log(xhr.status)
            if (xhr.status == 304) return;
            // or better: if (xhr.status != 200) return;
            // your code goes here
        },
        error: function () {
        // cartvine_is_ready = false;
        // // something happened and we cannto go on like this
        }
    });
(30 May '12, 02:26) RossCdH
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×125
×28
×10
×7
×1

question asked: 30 May '12, 01:53

question was seen: 3,212 times

last updated: 30 May '12, 02:46

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2021 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM