Some Web optimization ideas

Status
Not open for further replies.

PAC-humanoid

Wise, Aged Ars Veteran
127
[Slightly edited from http://www.realworldtech.com/forums/ind ... 7&roomid=2 --which received no response]

Three Web optimization ideas came to mind:

Sprited PNG:
By extending PNG with a new chunk type it seems it would be possible to use a fragment identifier (using '#') in a url to specify a sub-image within a PNG file without using CSS. This would have at least two advantages over CSS sprites. It would unify the sprite management to a single file, reducing the potential for inconsistencies; and it would allow meaningful names to be used in the url (e.g., "site-sprites.png#home_link"), incidentally avoiding the need for a dummy file url in the img/object tag (very minimal benefit).

This would obviously require adding support in browsers and might bloat the PNG file more than it would shrink the CSS, but the development advantages might be worth the bother
and cost.


Conditional-on-caching http push:
When a get request is made, the client could include a header indicating the cached content (including timestamp or version) for the site and/or subsection of the site. The server would have to indicate with each resource sent its caching nature (i.e., which collection it belongs to), and the caching client would have to manage items in a collection as a unit (or use a fallback method of individually requesting items).

The domain name could be used for site-wide resource collections and perhaps the file system directory structure might be used to indicate subsections (beyond subdomain divisions).

This feature would allow content to be provided as rapidly as if it was included for the uncached case (removing the justification of most included scripts and CSS) and in the cached case not only could bandwidth use and network latency be avoided, but the cached content might be cached in a pre-processed format, allowing it to be applied more quickly. The uncached case might also make more effective use of potential bandwidth by having a single large-window stream.


Support for signed rather than encrypted content:
One of the issues with https is the lack of distinction between private content (e.g., bank account information) and authenticated content (e.g., style sheets). Authenticated content can be the same for many people and so could take advantage of content distributors and proxy caches, but such content needs to be verified to assure that it is the correct content. It seems that it would be possible to include a digital signature with the url, so the client could be assured that the content was correct.

This would allow the client software to allow non-encrypted content to be considered 'secure', not requiring a warning.

(Unfortunately, this does not seem to mesh well with the above conditional push; a proxy cache would not be able to read the get request to service any possible cached content. This might be worked around by sending a non-encrypted http request which the server transforms to an https request, but that might add far too much complexity. There is also some danger that the content provider might not view some items as private [and send them as unencrypted but signed inclusions to save a little money] which the user does view as private but cannot easily see as being unencrypted. A worse danger would be a system that accidentally sends sensitive data unencrypted.)


Any comments?
 

drogin

Ars Tribunus Angusticlavius
8,284
Subscriptor++
As to the sprited PNG, the typical use for sprites is for things like background images, icons, etc. It isn't typically used for "content" images.

Using your approach you aren't saving anything because the browser would still be using multiple requests to get the parts of the image.

You can also do this in a relatively obvious way, i.e. create a server side component and use query string parameters to tell it what image you want.

e.g. /images/sprite.php?part=xyz

The conditional-push-cache idea frightens and confuses me. Are you saying that content is cached on the client side, and that the client asks the server if the cached data is still valid? I believe this is pretty much how it works.

If a server serves up a file, say a javascript file, and sets the Expires header to some future date then the client will not request that content again until the content is expired (or obviously if the user clears their cache).

You'll need to provide a more complete example.

Item three like-wise makes no sense and points to a general lack of understanding how HTTP works.
 

Faramir

Ars Legatus Legionis
36,356
Subscriptor
PAC-humanoid":8wzc9fdg said:
Support for signed rather than encrypted content:
One of the issues with https is the lack of distinction between private content (e.g., bank account information) and authenticated content (e.g., style sheets). Authenticated content can be the same for many people and so could take advantage of content distributors and proxy caches, but such content needs to be verified to assure that it is the correct content. It seems that it would be possible to include a digital signature with the url, so the client could be assured that the content was correct.

This would allow the client software to allow non-encrypted content to be considered 'secure', not requiring a warning.

Doesn't the header
Code:
cache-control: public
already take care of this concern?
 

PAC-humanoid

Wise, Aged Ars Veteran
127
drogin":2smtwtmv said:
As to the sprited PNG, the typical use for sprites is for things like background images, icons, etc. It isn't typically used for "content" images.

Using your approach you aren't saving anything because the browser would still be using multiple requests to get the parts of the image.

Why would such involve multiple requests? The client would recognize that the requests are the same in the same way that "some_page.html#some_section" is/can be recognized as the same document as "some_page.html#other_section".

drogin":2smtwtmv said:
You can also do this in a relatively obvious way, i.e. create a server side component and use query string parameters to tell it what image you want.

e.g. /images/sprite.php?part=xyz

But one wants to serve the entire PNG file.

drogin":2smtwtmv said:
The conditional-push-cache idea frightens and confuses me. Are you saying that content is cached on the client side, and that the client asks the server if the cached data is still valid? I believe this is pretty much how it works.

Existing caching only works for known specific resources. In the proposed case, certain resources are declared to be site-wide or subsite-wide. This means that a client--having previously visited "http://utopia.no/some_page.html" and cached the 'utopia.no' site-wide content-- when visiting "http://utopia.no/other_page.html" and indicated the cached content would not need to be sent the site-wide content; but if the client did not have the site-wide content cached, the server could push it with the request without having to wait for the client to parse the html and make the additional requests.

This avoids the need for always pushing content (e.g., as Google's main page, which includes a substantial amount of javascript). By allowing the client to declare that all the related resources are cached, the server need only send such resources when the client does not indicate they are cached or they have expired.

drogin":2smtwtmv said:
You'll need to provide a more complete example.

Was the above enough to clarify the intent?

drogin":2smtwtmv said:
Item three like-wise makes no sense and points to a general lack of understanding how HTTP works.

As I understand it (and I may well be wrong), https-served html which includes resources served by (unsecured) http generated (properly) a warning to the user. By serving the signatures of the included resources in the (secure) html, the serving of the included resources does not need to be encrypted and so can be distributed (in proxy caches, content-distribution networks, or external hosting sites) while still providing a reasonable guarantee that the content is valid (assuming the hash/signature makes it very difficult/impossible to generate deceptively meaningful content that matches the hash/signature).

The goal of the extension is to allow unencrypted resources to be included in an otherwise encrypted page without annoying (false but difficult to determine as false) warnings or loss of confidence in the validity of content (e.g., a cancel button will not look like an accept button).

Does that make my meaning clear?
 

PAC-humanoid

Wise, Aged Ars Veteran
127
Faramir":3mhzaenq said:
Doesn't the header
Code:
cache-control: public
already take care of this concern?

As I understand things, the user agent must notify the user that some of the site's content is insecure if it is not served by https (to avoid possibly forged content). If the content was signed, it could be served 'insecurely' but still be trustworthy (because the content must pass the signature test).

Insecure serving facilitates distributed content (as well as avoiding unnecessary overhead in setting up a secure channel and encrypting/decrypting the content).
 

NickR

Ars Scholae Palatinae
708
One general consideration is have you got measurements to show if/where there are any performance issues and justify the effort of implementing any optimisation ?

How would the results compare to throwing more hardware at the problem (sometimes development cost is a bigger factor than hardware costs)?

One big alternative/complementary option to image sprites is to off load images to an optimised server/service, be it a CDN or a separate server.

Another alternative to consider from image sprites, conditional on-caching is to simplify the pages design to use less images and less markup and even CSS. The could have useful side effects of less images/html to maintain.

Cheers, Nick
 

PAC-humanoid

Wise, Aged Ars Veteran
127
NickR":32lnnv0l said:
One general consideration is have you got measurements to show if/where there are any performance issues and justify the effort of implementing any optimisation ?

No, nor do I have the means of acquiring such measurements much less making a meaningful comparison against the cost of developing such features and having them adopted.

[Edit: changed "comparison of" to "comparison against"]

NickR":32lnnv0l said:
One big alternative/complementary option to image sprites is to off load images to an optimised server/service, be it a CDN or a separate server.

Such would seem to be complementary. Sprites have the advantage of reducing the number of requests.

By the way, the sprited PNG idea is almost entirely a developmental aid (there would be at most minimal bandwidth or resource count advantage over CSS-based sprites); it keeps the image content in one file--helping to avoid inconsistencies--and provides a meaningful-to-humans url in the img src attribute.

The use for sprited PNG would also be almost entirely removed if the second idea (about pushing multiple resources in response to a single request) was broadly adopted, but the idea of sprited PNG seemed like it would be easier to implement.


NickR":32lnnv0l said:
Another alternative to consider from image sprites, conditional on-caching is to simplify the pages design to use less images and less markup and even CSS. The could have useful side effects of less images/html to maintain.

Yes, I certainly agree with that! However, I suspect that the push idea would have some use even with a simpler design because there is an increasing emphasis on dynamic interfaces (using javascript) and the desire for minimal latency is currently driving some to include scripts and css (which could otherwise be cached independently) in the html.

By the way, any comment on the signed content idea?
 

Ice^3

Ars Tribunus Militum
2,634
PAC-humanoid":gmvk1q47 said:
As I understand it (and I may well be wrong), https-served html which includes resources served by (unsecured) http generated (properly) a warning to the user. By serving the signatures of the included resources in the (secure) html, the serving of the included resources does not need to be encrypted and so can be distributed (in proxy caches, content-distribution networks, or external hosting sites) while still providing a reasonable guarantee that the content is valid (assuming the hash/signature makes it very difficult/impossible to generate deceptively meaningful content that matches the hash/signature).

The goal of the extension is to allow unencrypted resources to be included in an otherwise encrypted page without annoying (false but difficult to determine as false) warnings or loss of confidence in the validity of content (e.g., a cancel button will not look like an accept button).

Does that make my meaning clear?

It makes sense and it's true. Mozilla uses a similar system to distribute add-ons off of non-ssl public mirrors (the hashes are distributed on the SSL pages). For assets in your page it sounds like a huge pain in the ass to deal with. You'd have to have a templating system that put your signatures in automatically and could deal with expiring caches or no one would want to maintain it. Honestly, I'd rather see everything over SSL for small assets like these.

For the record, even though some people are hating on you in this thread, I like that you're thinking outside of our current standards. :)
 

drogin

Ars Tribunus Angusticlavius
8,284
Subscriptor++
PAC-humanoid":2ve52qdx said:
drogin":2ve52qdx said:
Item three like-wise makes no sense and points to a general lack of understanding how HTTP works.

As I understand it (and I may well be wrong), https-served html which includes resources served by (unsecured) http generated (properly) a warning to the user. By serving the signatures of the included resources in the (secure) html, the serving of the included resources does not need to be encrypted and so can be distributed (in proxy caches, content-distribution networks, or external hosting sites) while still providing a reasonable guarantee that the content is valid (assuming the hash/signature makes it very difficult/impossible to generate deceptively meaningful content that matches the hash/signature).

The goal of the extension is to allow unencrypted resources to be included in an otherwise encrypted page without annoying (false but difficult to determine as false) warnings or loss of confidence in the validity of content (e.g., a cancel button will not look like an accept button).

Does that make my meaning clear?

So how does the signature get generated and then validated?

If the secure channel provides the signature of the unsecure asset, wouldn't the browser have to get the entire asset in order to calculate the signature and verify it's the same?

I would think that once you start loading insecure data into memory, there is a chance for a security issue.
 
If you just want authentication (making sure the content hasn't been tampered with), it suffices to get both the content and signature over an insecure channel (HTTP) - you don't need to get the signature over HTTPS. In fact, this scenario is exactly what authentication is designed for. However, by doing this you're basically reinventing part of HTTPS (and exposing one of its shortcomings AFAIK, which is that you can't enable encryption and authentication independently; could be wrong about this though).

drogin":2hidjp9e said:
So how does the signature get generated and then validated?
Same way it would ever be.

If the secure channel provides the signature of the unsecure asset, wouldn't the browser have to get the entire asset in order to calculate the signature and verify it's the same?
No, there are digital signature algorithms that are optimized for streaming and you could always chop a bit string x into blocks x1, ..., xn and sign n, (1, x1), ..., (n, xn) independently instead of just signing x.

I would think that once you start loading insecure data into memory, there is a chance for a security issue.
The remote site can send you maliciously crafted crap regardless of whether you're using HTTPS. The only difference is with HTTPS, it's maliciously crafted crap purporting to be encrypted and signed, but you still need to load it to check the signature and decrypt.
 

drogin

Ars Tribunus Angusticlavius
8,284
Subscriptor++
With HTTPS, isn't the signature used to identify the web server and not the content?

The idea is that the signature of the server is signed by a "trusted" authority.

With the scheme being described, there is no independent trust, or at the very least you are assuming the trust transfers.

What PAC is describing is that you trust server A, and server A tells you to trust something else (e.g. unsecured content from itself).

Whether you can get a signature from the unsecure content isn't the important part. The important part seems to be that you trust the certificate.
 

Faramir

Ars Legatus Legionis
36,356
Subscriptor
drogin":6z4zebbv said:
With HTTPS, isn't the signature used to identify the web server and not the content?

The idea is that the signature of the server is signed by a "trusted" authority.
The certificate is to verify that the client is talking to the correct server and also used to set up a tamper and eavesdropping resistant channel using an symmetric cypher for all further communication.

If both client and server are setup to use an appropriate suite it is possible to reduce the security such that you only get tamper-resistance and not eavesdropping resistance.

The configuration file would have a line something like:
RSA PLAINTEXT HMAC-SHA256
 

technophile

Ars Legatus Legionis
23,768
drogin":2m3ovv1s said:
The idea is that the signature of the server is signed by a "trusted" authority.

With the scheme being described, there is no independent trust, or at the very least you are assuming the trust transfers.
The rest of the discussion aside, there's no independent trust now. If you think you can trust a certificate just because it was properly issued by a "legitimate" CA, I have a bridge in Brooklyn to sell you.
 

drogin

Ars Tribunus Angusticlavius
8,284
Subscriptor++
technophile":1elwa79d said:
drogin":1elwa79d said:
The idea is that the signature of the server is signed by a "trusted" authority.

With the scheme being described, there is no independent trust, or at the very least you are assuming the trust transfers.
The rest of the discussion aside, there's no independent trust now. If you think you can trust a certificate just because it was properly issued by a "legitimate" CA, I have a bridge in Brooklyn to sell you.

Hence why I said, "the idea is". It's obviously the intent of HTTPS to be a secure protocol, whether it succeeds at it is another matter entirely...
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
If you just want authentication (making sure the content hasn't been tampered with), it suffices to get both the content and signature over an insecure channel (HTTP)

Assuming the signature is via a certificate for which there is a previously established trust this is still a whole bunch of fun with resends...

Assuming Alice sending data to Bob, authenticated as okay with signature. Evil Eve captures this.
There is some bug in this data that can be exploited, perhaps a hardcoded domain name that the attacker can take control of, a reference to something else, who knows[1].
Eve can now replay those bits into a session between Alice and Bob, replacing parts as desired if the encrypted part reuses the same name to identify the resource.

I assume SPDY deals with this in some way (assuming it's well designed)

1. the point here is that the potential surface is vast, and people using this simply won't realise that they must make extra sure that what they put in this stream is implicitly trusted for a very long time, by all users of the system...
 
Of course. Authentication ensures that the server generated the content, not that it's the correct content. For the latter the client could generate a random string that the server includes in the response and the server also includes the request and sighs everything.

It's important to first define what you're trying to do and then prove security by reducing breaking the protocol to breaking some cryptographic primitive or hardness assumption. (unfortunately we don't even know whether signature schemes exist...)
 
Status
Not open for further replies.