Welcome back. In the last lecture we ended with the divisibility relation. So, let us quickly go through that. Let us just repeat. If you have two natural numbers A and B and if you are able to write A as B into C for yet another natural number, then we say that B divides A. And we will write it in the short form as B vertical bar A. However, while reading that short form we will still read it as B divides A. And in the last lecture we actually saw a quick proof that 1 divides A for every natural number as well as A divides A for every natural number. So, every natural number comes equipped with two God given divisors. There is one and there is the natural number itself. So, let us just go to the next slide where we see that like the subtraction, divisibility also gives you an order. You may wonder that I have been talking about order relations. So, is there a definition of the order relation? Indeed, there is a definition of in fact, not just of an order relation, there is a definition of a relation. What do you mean by two elements in a set being related? Once you see that definition, then the order relation should come with some more properties. It should be a relation with some more properties. So, I will just invite you to go and read somewhere maybe in some basic book or you may want to search on the internet or maybe Wikipedia will help you in that. But those definitions are not important for us at the moment. What we are going to do is concentrate on this very specific order relation, the relation of divisibility. And as we observed in the last lecture also, we do not have a trichotomy here. You can have two natural numbers say 2 and 7. Now, 2 does not divide 7, 7 does not divide 2 and of course, 2 and 7 are not the same. So, given any two natural numbers, we cannot say that a equal to b or a divides b or b divides a. However, when the situation is not normal, that is when things get interesting. So, this is what will give us our basic definition, the most fundamental definition that of a prime integer and then primes come equipped with many fantastic properties as we will see later. So, before going to do that, let us again warm up ourselves with some very basic properties of divisibility. I am going to list them on the next page and just like the last lecture, we will try to prove them one by one. These are the three properties. What does the first property say? It says that if you have a dividing b and b dividing c, then a divides c. This is encoded by saying that the order relation is transitive. If a divides b and b divides some another natural number c, then a should divide c. What does the next property say? It says that if a divides b and I multiply both sides by a natural number c, then the division relation is preserved. The multiplication will preserve the division relation. You may ask, what will happen if I add a number? If a divides b and you add an integer, is it true that a plus c divides b plus c? If I have not written that property, maybe there is a possibility that this property does not hold. Why do not you think about this for a while? After this lecture is complete, you may think about this, does it hold that a divides b and I add any integer c, any natural number c to a and b and yet we have that a plus c divides b plus c. Think about this. What is the third property? Third property tries to combine the divisibility relation with the earlier relation. This is a thing which is omnipresent in mathematics. You will see that everywhere whenever we are developing a theory, we will introduce some concepts and each time we introduce a new concept, we will try to relate it with the earlier concepts. That is what makes mathematics more interesting. You will not see us introducing one concept after another and not seeing the properties of what happens with respect to one concept and the other concept. This is very nice about mathematics. So, the third property says that whenever I have a dividing a b, remember we are within the set of natural numbers. Whenever you have a natural number a dividing a natural number b, then it should happen that a is less than or equal to b. So, it tells you when you turn this statement around, it will tell you that if you have a number a which is bigger than some number b, then this bigger number can never divide the smaller number. The statement I have just said is equivalent to the statement we have seen here. So, there are these three properties. We will try to go over them one by one and prove them one by one. So, here comes the very first property. If a divides b and b divides c, then a divides c. Like our last lecture, I am going to give you a minute to think about this proof and then after that I will give my own proof. Well, my meaning the one that is there in most of the books. If you have any other proof, then the one that I am giving please write to me and let me know your proof. So, I have given you your minute and now let me give you my proof. So, here goes we want to prove that the divisibility relation is transitive. Proof we have equal to a d1. It is given that a divides b. So, b has to be of the form a into some natural number d1 and c equal to b into d2 for some d1, d2 in n. This is what we must have. If you have a divides b and b divides c, then we should have that b is a into a natural number, c is b into possibly another natural number we do not care. So, we have b is a d1 and c is b d2. Then in this equation I will take the value of the b that we have got here. This is a d1 into d2 which is same as a into d1, d2 and note that d1, d2 being product of two natural numbers is a natural number itself. So, we have written c as a into a natural number and hence a divides c. So, we have proved that when a divides b and b divides c, then a must divide c. Let us go to the next property if a divides b and c is a natural number then ac divides bc. So, multiplication by natural number respects the divisibility relation. Once again as we have our deal I will give you a minute to think about this proof. Quite likely you will get the proof that I have in mind which is a very good thing that will tell us that we are thinking in the same direction or even more interestingly you may have a different proof and I would like to know that different proof. So, your minute starts now. So, your minute is up and let me now attempt to give you a proof. We are given that a divides b. So, we have b equal to a into d for sum d in n, a divides b. So, b is a into a natural number. Now to this equation we can multiply by c. So, we have bc equal to ad into c which is same as ac into d. So, therefore we have written bc which is a natural number as ac into a third natural number which clearly says that ac divides bc. Whenever a natural number a divides another natural number b and to both sides you be fair to both the natural numbers which are there on either side of the vertical bar. You multiply by a natural number to both these natural numbers then the divisibility relation is respected. We now go to the third property which is a very important property and we will use it quite often. This says that if you have a natural number a dividing a natural number b then with respect to the earlier order that we have defined less than it should be less than or equal to b. This strange symbol that you may see here means that either a is less than b or a is equal to b. Once again I will give you a minute to think about this proof and after your minute is done I will state my proof. Your minute is up. So, let us see the proof. This proof is quite interesting. How would we prove this? So, let us see. So, since divides b we have b equal to ad sum natural number d. So, we have b as a product of a and a natural number d. Now this natural number d that you have got could either be equal to the number 1 or it could be bigger than 1. So, if d is 1 then b is a into 1 which is a. This is one case that b is equal to a.  How many times do we get this? This is d times. We have that b is a into d. So, b is a plus a plus a d times. What we want to prove is that if you have a dividing b then a is less than or equal to b. This is what we want to prove and we have already seen that when d. So, b is a into d if d is 1 then a equal to b. If d is bigger than 1. Observe first of all a plus a is bigger than a. If I have a natural number a and I add the natural number to itself I get something which is bigger than that and then inductively I get a I am adding a to both these sides. And we know that the addition respects the bigger than sign or the less than sign. But what is also true is that it preserves the transitivity is preserved. That means if you have a natural number which is bigger than second natural number which is bigger than the third natural number. Then we see that the difference of the first one and the third one is a natural number and therefore we have transitivity. This way d into a I will just write it as d into a which is a plus a plus a d times is going to be bigger than a and remember our b was d into a or a into d. This completes our proof. Once again there were two possibilities either you could write b as a into 1 in which case you get equality or you could write b as a into a d which is bigger than 1.  So, let us just repeat what we have proved until now. We have proved that when a divides b and b divides c then a divides c. This says that the divisibility relation is transitive. Further if you have a dividing b and you multiply both sides by a natural number c then we will have that ac divides bc.  These three are very important. There might be some extensions of these properties for the set of integers for the set z. In fact, you could go all the way up to the set of real numbers, complex numbers or if you know some advanced mathematics the number of the quaternions what are also known as Hamiltonions all the way up to wherever you can go. But at the moment what we have is the following. If you have two natural numbers then we say that one natural number divides the another natural number. If there is a third natural number such that the first one can be the second one can be written as the first into the third. Now, brace yourself we are coming to the most important definition in the basic theory of numbers which is as follows. This is the definition of a prime. Really the English word prime has very good meaning it is you know something which is in the best of its situations. And prime number is really the best thing that you can have in the number theory. So, what is the prime? We have observed that whenever you take any natural number a there are two God given divisors one divides it and the number a divides it. If your natural number happens to be just the number one then there is only one God given divisor because both these divisors happen to be the same. In any case any number bigger than one is going to have two divisors which are given to us always and we say that a natural number is a prime if there are no further divisors. So, we say that our natural number p is a prime if there are exactly two divisors not one, not three and not further no 4, 5, 6, 7. So, once we have made a definition a natural thing would be to see some properties maybe prove some results but before that we should see examples. Let us go over our numbers we are working with natural numbers. So, we will start from one and go onwards. Let us start from one go onwards and see if we get a prime is one a prime. What would you think? How many divisors are there for one? We saw just now that for one there are no two divisors because for any integer for any natural number a there are two divisors one and a but one unfortunately has the property that both these divisors become the same. So, the number of divisors of one in n is one. One is the only unfortunate number in this way. So, one cannot be a prime one is not a prime. What about the next number? Is two a prime? How many divisors are there for two? One is a divisor of two. Two is a divisor of two. Is three a divisor of two? What did we learn in the last property of divisibility? If three divided two then three would have to be less than or equal to two. But three minus two which is a natural number one tells us that three is bigger than two. Similarly, four, five, six, seven all numbers are bigger than two. So, if you are looking for divisors of two you should go no further. This is something you should take a note of. If you are looking for divisors of a number a you need to go only up to a. You do not have to consider the natural numbers from a plus one onwards. So, it has become a finite problem. To find the divisors of a you have to go no further than a. In fact, you can make this problem simpler. You need to go only up to the square root of a but that will come when we deal with really large numbers. So, is two a prime? We have counted the number of divisors of two. One is a divisor and two is a divisor and there are no further. So, two is indeed a prime. What about three? Is three a prime? One divides three, three divides three. We need to look no further. So, four onwards are the natural numbers that we will ignore. There is another number sitting between one and three which is two. Does two divide three? How do they multiples of two look like? Two into one is two. Two into two is four. Two into three is six. So, the higher natural number you multiplied by to two you get bigger and bigger numbers. So, two into a natural number is not equal to three. Therefore, two does not divide three. So, the divisors of three are one and three nothing further. So, three is also a prime. What about four? Can you think about four being a prime? We will need to look at the divisors of four. One is a divisor, four is a divisor but we have counted the divisors of the multiples of two just now and we saw that two into two is four. So, four has three divisors. One, two and four itself. So, four is not a prime. All right. So, we got one is not a prime, two is a prime, three is a prime, four is not a prime. You may continue this way. Can we list all primes up to 100? Well, the way we have done so far, this should be a work which is possible. So, yes there are 25 of them. Can we list them all? 2, 3, 5, 7, 11. This is the next bunch. This is the next bunch. This is the next and this is the last bunch. So, these are exactly the primes up to 100. You know, you would see a teacher in your class giving you a problem and if you solve it very easily, the teacher will give you a slightly harder problem. I am going to do the same. Can we list all primes up to 1000? The answer is yes. There are 168 of them. The number of primes up to 100 was 25. The number of primes up to 1000, we have multiplied 100 by 10. So, we got 1000. The number 25 did not get multiplied by 10. It got multiplied to somewhere between 6 and 7. So, we got 168. I am not going to write all those primes here. I will give that to you as an interesting homework. Do not send that list to me. Keep it with you. Can we list all primes up to 10000? Yes, we can. I can tell you the number. There are 1229 of them. Once again, we went from 1000 to 10000 by multiplying by 10 and the number 168 did not get multiplied by 10. It got multiplied by a number which is slightly smaller than 8. So, after 10000 you may ask what about 100000? What about 100000? Or can we just go on and on? Can we just go on and on? And the answer is yes. We can. What this means to say is that there are infinitely many primes out there. There are plenty of primes. The set of primes is not finite. With this punchline we will stop here in this lecture and we will state the result of the infinitude of primes in the next lecture and also see a proof. Thank you.


Gamma 4, gain 1. Gamma 2, gain 1. Zaire Basin, they're in here, right here. They'll familiarize themselves with the landmark from this photograph and then they'll be able to recognize it from here. Can you tell us if you've cleared out the tag straight, because we'd like to start uplinking another DTO set of messages on the Teters West. Yeah, we did. We cleared it out. Looks like they came out really good. In particular there were a couple that you sent up. Wades of gray were very good. All the weather charts came out real good. And all of the message traffic came out very legible and good also. They're laying in the tray very nice. Looks like tags is working like a charm.


Welcome back to our lecture series Math 3120, Transition to Advanced Mathematics for Students at Southern Utah University. As usual, I'll be your professor today, Dr. Angel Misseldine. In this video, we're going to continue our discussion of modular arithmetic and actually justify why we refer to it as modular arithmetic. In order to do so, let me remind you of a few facts. Imagine we have some elements a and b, where a and b are themselves integers, and we have some other element n which is a natural number. Then we define a relation a is congruent to b modulo n, and this symbol right here means that n divides the difference of a and b. We've talked about last time how this forms an equivalence relation. We use the symbol bracket, a number bracket here to represent the equivalence class. This would be the collection of all numbers of the form a plus kn, where k is honestly any integer whatsoever. This gives us the equivalence class with regard to this equivalence relation. We call this a congruence class. In fact, you can always choose this number a, so that it sits between 0, inclusive and n, exclusive there. We get all the numbers 0, 1, 2, 3, 4 up to n minus 1, because the idea we also discovered that two numbers are equivalent, they're congruent mod n, if and only if they have the same remainder if you divide by n. By the division algorithm, these are the options you have for remainders. Given a positive integer, zn, we then define to be the set of all congruence classes, and this is going to be a set that contains exactly n elements. Then what we want to talk about right now is how this set zn actually defines a finite arithmetic that in many ways resembles the arithmetic of the integers. Also, in many ways, the arithmetic of the rational numbers, but let's first define what I mean here by arithmetic. What we're going to do is for this set zn, we're going to define two operations on that set. The first one we're going to call modular addition, and the second one we're going to call it modular multiplication. Again, let n be a natural number. Then we define addition modulo n to be an operation on the set zn such that we can define the sum of two congruence classes to be the congruence class of their sum. Sometimes you'll see this symbol out here, where people use this O plus. That's actually the latex symbol there, O plus. It sounds like a streaming service there. Come check out the new math videos on O plus. That's totally what I should name this channel here. Anyways, if you take the sum of two congruence classes, you then define that to be the class that contains the sum of the two things. We do the same thing for multiplication. We can multiply together two congruence classes to produce the congruence class of their product. Some people don't bother introducing a new symbol for these modular operations. That's fine and hunky-dory if you want to, but for us, this is what we're going to do here. Whenever you add together a congruence class, we'll use this O plus, and this represents then the class of the sum, and O times here represents the class of the product. So we come up with these two operations. So we're taking, and by an operation, what I mean here is we take two objects and then combine them into a new object of that same set. So the congruence class containing A and B belong to ZN, and the congruence class containing A plus B also produces an object of ZN. So you combine two objects inside of a set to produce a third element of that set. Same thing with multiplication happening right here. Now with an operation, it's customary, especially with finite operations, to actually arrange all the symbols in a table format. So I want to explain what this means right here. So look at this addition table with respect to modulo five. So we see on the left here, the modular addition table for Z five. What this means is we're going to add together numbers, modulo five. And so how you read this is the rows right here represent the sum and on the left. And then these elements right here that denote the columns, this represents the second operand. And so if you were to look at a specific place in the table, like take this number right here, this number, if you look at the row, if you look at the column, what this tells us is that two plus three is equal to zero. And we're thinking of these as congruence classes. All right, so the congruence class of two plus the congruence class of three is equal to the congruence class of zero. But of course, this notation can get awkward really quickly. So most likely how we would write it would be is two plus three is congruent to zero, mod five. And so that's what that statement means right there. Cause after all, two plus three is equal to five and five has this, well, five is congruent to zero. We always want to reduce things modulo five. So we always have a number between zero and four as we work through these. Give you another example here. If you take this one and this one right here, the way you want to read this is that three plus four is congruent to two, mod five. And again, if the modulus is clear, we don't write it out every single time there, but two plus, our three plus four is congruent to two, mod five. We can do another one here, zero, for example. Zero plus zero is congruent to zero. If you take zero plus one, that gives you one. If you take zero plus two, that gives you two.  So something to notice here is that zero has the property that if you add zero to any, any number M, you always get back M, mod whatever, right? And so modular arithmetic does in fact have an additive identity element. We'll say some more about this in a second. We also have the property that if you switch the order, it doesn't matter. Like if I take two and three, which adds up to be zero, this is the same thing as three plus two, which is equal to zero. This operation of addition turns out to be commutative. You can actually see this from the table here, because after all, we take three plus two versus two plus three, you get the exact same number. Like if you reflect across the diagonal, you always end up with the same number, things like that. There's other properties here. We'll talk about those in a moment. The other properties are a little bit less obvious when it comes to the table here. But again, if you take something like two plus one, this is congruent to three. But if you take something like four plus three, that's congruent to two. And the idea there is four plus three is equal to seven. If you reduce seven, mod five, you get a remainder, which is then two. And that's how these calculations are. You just compute the number as a regular integer, four plus four is equal to eight. When you reduce eight, mod five, you end up with three. Because three is the same thing as eight, mod five, because eight is actually equal to five plus three. And you ignore multiples of five when you work mod five. Let's look at multiplication for a little bit here. This time we're gonna switch to be mod eight. So we're looking at the multiplication tables in Z eight. So there's eight objects here. And so I'm just gonna write the remainders here, because these are congruence classes, but I'm just gonna write the remainders zero through seven. So we have zero, one, two, three, four, five, six, seven, like so. Again, the rows are gonna be the first operand. The columns will be the second operand. And you see the labels right there. I indicate the operation here. So you know this is a multiplication table. And not shockingly, we see that zero times anything is equal to zero. This happens with integers. It'll happen with integers mod eight as well. We also can see that one acts like a multiplicative identity. Notice how you look at the index row right here. It tells you which column you're in. That's identical to this row right here. One times anything. So one times M is gonna be congruent to M mod N. And so one acts like a multiplicative identity for modular multiplication, much in the same way that it does for integers as well. And so some other things we could see here. If I take three times six, three times six is equal to two. Or I should say three times six is congruent to two, mod eight. If we did another one, six times two. Well, as an integer, six times two is 12. But if we reduce 12 mod eight, we end up with four. And so that's been the product. Six times two is congruent to four here. Now, some curious things to note here. Again, this thing is symmetric across the diagonal. Therefore, it is a commutative operation. Again, we'll talk about some of the properties more in a little bit. But one thing that's kind of curious is the following. Take, for example, four times two, mod eight. This product is equal to zero. And I want you to think about that for a moment. Four is not congruent to zero, mod eight. And likewise, two is not congruent to zero, mod eight. But four times two is congruent to zero, mod eight. Because four times two is actually equal to eight. As an integer, as you reduce that mod eight, you get back a zero here. And so this is a curious property because in algebra classes, when you're working with real numbers, complex numbers, you often have something called the zero product property. The zero product property is very useful because you're using this assumption that any product of real numbers, if it equals to zero, it was because one of the factors was already equal to zero. That's the only way you can get a zero product is that one of the factors is zero. But with regard to modular multiplication, this table does seem to suggest there is a possibility where you can have a product of two non-zero quantities that become zero. So things like the zero product property can fail in that situation. Another curious thing to note here, I want you to notice again when you look at four here, four times two is equal to zero. Four times four is equal to zero. Four times six is equal to zero. Notice how there's more than one product that if you take the factor four, for example, fixed on the left-hand side, if you take the second factor, you can vary that, but you can still get the same product over and over and over again. Similar here, if you look at four times one, that's equal to four. If you take, for example, four times three, that's also equal to four. And so this is a curious thing here that you have multiple things that multiply by four that give you back four. You can't cancel them out. I'll give you another example of this, for example. Take two, two times three is equal to six, but likewise, two times seven is equal to six. So for example, if you had an equation, two x is congruent to six mod eight here. There's actually two solutions here. One solution is three and one solution is seven, which is curious because isn't this a linear equation? Right? This looks like a linear equation. Two x is congruent to six, but how does a linear equation have two solutions? That's kind of a weird thing. And that's the thing that I'm trying to emphasize here that the arithmetic you get when you work with modular arithmetic in many aspects, it behaves just like you would expect with the integers, but in many aspects, things can get weird and has entirely to do with the modulus itself. What we're talking about right now is very much at the beginning of topics like number theory and abstract algebra. Number theory is very obsessed with this modular arithmetic and abstract algebra is very obsessed with just arithmetic in general. That is abstract algebra loves studying binary operations. So things like O plus and O times are very much an interest in a situation like that. So while there are some anomalies that seem to happen with modular arithmetic, let me give you some properties that are absolutely true that you can use when you're working with modular arithmetic of any kind. So let N be a natural number and that does include zero and one, let ABC be any integers, then the following properties hold. So first, the associative property for addition holds, that is if you take A plus B plus C, this is congruence to A plus B plus C mod N. And I am using the O plus right here, even though I don't have congruence classes to really emphasize this is modular addition that has this associative property. It doesn't matter how you do parentheses. Same thing with modular multiplication, it is also associative. A times B times C is congruence to A times B times C mod any N whatsoever. Modular addition and multiplication is also commutative. A plus B is congruent to B plus A and A times B is congruent to B times A. With regard to addition and multiplication together, the distributive laws hold.  So this is the left distributive law. You also have the right distributive law. A plus B times C is the same thing as A times C plus B times C. We have identities here. There is an additive identity. We talked about that earlier. There is a number, in this case it's zero and this is true for any modulus whatsoever that A plus zero is congruent to zero plus A which is congruent to A. And for multiplication one acts like the multiplicative identity. A times one is congruent to one times A which is congruent to A. And then lastly, we have a property about inverses that with regard to modular addition, there are inverses that if you take the element A and you add to it N minus A, this always gives you zero, right? And that's a very simple calculation to do here. And we write N minus A because we like to represent these numbers using the possible remainders, zero through N minus one, right? So if we were working mod five, for example, then if I talk about what is negative two, negative two is the same thing as three, where three of course, we got that as five minus two. Five minus two is three. So you always get an additive number, an additive inverse here. So even though we keep our numbers in the non-negative representations, we can actually think of modular arithmetic includes negative numbers as well. Negative two is the same thing as positive three when you work mod five. Now, how does one prove these properties here? How would you prove a property about modular arithmetic? And it comes honestly down to just the definition. If you want to prove that these two things are congruent to each other, it's like, well, congruence is an equivalence relation. So to show the additive principle here, the additive associativity, you would have to show that the difference of these two numbers, this number minus that number is divisible by N. All right, so here's the proof of modular associativity of addition. So consider the number A plus B plus C minus A plus B plus C. Well, because integer addition is associative, these two numbers are one and the same thing as in the whole number is this whole number as well. And thus their difference is equal to zero. And zero is equal to zero times N. So N does divide the difference of these two numbers. And so then that tells us, with regard to the congruence relation here, that these two numbers are congruent. So A plus B plus C is congruent to A plus B plus C, right? In particular, if two numbers are equal as integers, then they will be congruent with respect to modular operations as well. And that's honestly how the proof of all of these things happen. Pretty much all of these ones, because these are equal as integers, they're gonna be equal with respect to these modular integers as well. And that's where the first eight properties follow. And so I'm gonna leave it as a proof to the viewer here to prove the remaining properties here. The one exception to this would be property, well, the inverse property here. We're not saying, because this property does not hold, this property does not hold for regular integers. Like if you take A plus N minus A, you could back N, which is not usually zero. But of course, when you're working with modular arithmetic, you just wanna find a multiple of N. The key thing about modular arithmetic is that multiples of N are considered zeros. And so we can get away with that here. What about the gap right here? Why wasn't there a multiplicative inverse property here? Well, it turns out there are some problems when it comes to modular division. Now I should say there does exist such a thing as modular subtraction. We can do an O minus, right? So what does it mean to take the congruence class of A and minus from it, the congruence class of B? Well, clearly you see that this should be defined to just to be A minus B, right? But this could be problematic, right? Is this number A minus B gonna be a number that's within the range zero through A minus one? Well, maybe, maybe not. It doesn't matter though. This congruence relation is defined for any integers. So we can define modular subtraction no big deal. But if you were concerned whatsoever, the key thing here is modular subtraction is really just modular addition. But we're looking at the inverse, right? So what does it mean to subtract? Well, subtraction is just adding a negative, which is really adding inverses. If you have additive inverses, then you have subtraction. Okay, but what about division? Division can be problematic because if I'm trying to define something like, we're gonna take A divided O divide by B, you would want that to be like A divided by B, but the thing is A divided by B itself is likely not an integer. And therefore, this is nonsense. Like that symbol doesn't necessarily mean anything. But it turns out there are situations through which we can divide integers in a modular fashion. It turns out that we do get multiplicative inverses exactly when the number A and the modulus N are relatively prime with each other. So the number A has a multiplicative inverse inside of ZN if and only if the GCD of the numbers A and N is equal to one. And the reason for that basically comes down to the Euclidean algorithm, okay? If the GCD of A and N is equal to one, that means there exist integers R and S such that AR plus NS is equal to one. This is given to us by the Euclidean algorithm. But if I take this one is equal to AR plus NS, this second number AR plus NS is clearly congruent to AR when you look at mod N here because you can kill off the multiple of N. Therefore, we have a number R, which when times by A gives you back the multiplicative identity. This is exactly what one means by a multiplicative inverse. And these directions go in both directions if and only if. And so therefore, integers that which have a GCD equal to one to the module. So that is those integers which are co-prime to the modulus, they have inverses. And in fact, the Euclidean algorithm tells you what that inverse is gonna be. The inverse, the multiplicative inverse is the coefficient that you connect to A with this linear combination. If you can find a linear combination of A and the modules that equals one, you then have the inverse. And I wanna show you how you can use this and then solve modular equations. So consider the equation 2X plus one is congruent to five, mod seven. How would you solve this for X? And so we're gonna go back to some fundamental algebraic observations here. If I wanted to solve the equation 2X plus one equals five, the first thing I would do is I would add negative one to both sides. Why am I adding negative one? Because negative one is the inverse of one. So we're gonna add negative one to both sides, okay? On the right-hand side, you're gonna take one plus, sorry, five plus negative one, which gives you four, mod seven. On the left-hand side, we use the associative property to redo parentheses so that 2X plus one plus negative one becomes 2X plus one plus negative one. Now, one and negative one are additive inverses. They simplify to be zero. And zero is the additive identity. So if I add zero to 2X, I just get back 2X. So now we have the simplified equation 2X is congruent to four, mod seven. Those properties we used beforehand, the inverse axiom, the identity axiom, the associativity axiom, they allow us to get rid of the one on the left-hand side to help us solve for this. Now, if we wanna get rid of the two, we have, when I say get rid of the two, we wanna move the two to the other side of the equation, much like how we move the one to the other side of the equation, and in order to do that, we need to have inverses, associativity and identities. Now, for multiplication, we do have associativity. We do have identities, but do we have inverses? Sometimes, sometimes not. But you'll notice that two is co-prime to seven. The GCD of two and seven is equal to one. So by the Euclidean algorithm, there does exist a number, there exists a linear combination of two and seven that gives you one. And you can either run the Euclidean algorithm or a little bit of guess and check, you can see here, that four times two, which is eight, minus one times seven will give you one. Eight minus seven is equal to one here. And so this tells us that the multiplicative inverse of two, mod seven, is four. Two to the negative one power is congruent to four here. So if I multiply both sides of the equation by four, this is gonna cancel out the two. And let's see the details of this thing here. So I'm gonna times both sides by four. On the right hand side, you're gonna get 16, four times four is 16. 16, of course, is the same thing as, well, 16 is the same thing as two plus 14, is a multiple of seven. So 16 and two are congruent to each other, all right? On the left hand side though, we're gonna take four times two X by associativity, you get four times two times X, four times two is eight, but eight is congruent to one, mod seven, because again, eight is equal to one plus seven, ignoring multiples of seven, we end up with just a one there. And so we were able to solve this linear equation because we had a multiplicative inverse. That example we were looking at earlier, when we were working mod eight, we had a problem with two X is congruent to, what was, with three, something like that, or six was what it was, working mod eight. There was a problem there because there was two solutions. X could equal three, right? And then X could also equal seven. Two times seven is 14. If you subtract eight from that, you get back six. You had multiple solutions. The issue had to do with the fact that our coefficient was not co-prime with the modulus, the GCD of two and eight is equal to two. And that does cause some issues with regard to modular arithmetic. So in many ways, it does behave like the integer arithmetic we're used to, but in many ways it also behaves a little bit differently. And that's about as far as we're gonna get in this lecture series with regard to modular arithmetic. I want to introduce it so we can use this as a toy to prove some facts about, but in the end, the deeper studies of modular arithmetic belongs to undergraduate mathematics classes like number theory and abstract algebra, for which there are some abstract algebra videos on this YouTube channel. So feel free to watch those if you wanna learn some more about modular arithmetic.


All right, so let me get started with today's presentation on on web performance. As I said, this is not a prescriptive conversation. This is a conversation of understanding how fundamentally the web works and applying those concepts to your own websites and all. I'm going to use the the weirdest tool for presentation, which is a Google sheet. Tejas, can you confirm if you can read and see the sheet? I can, yes. Okay, so I'm assuming that everyone else can also. So I'm going to use this. I've just jotted down some notes. It's expected to be like a free form, freewheeling chat. It's not a very formal presentation. I start with what is web performance. I'm not going to touch upon the point that web performance is important. The reason I'm not going to touch upon the point where performance is important is because it's almost an established fact and the fact that you're curious and interested in this. That's why you're here, but there are going to be lots of things around the web, but that web performance is important. But what exactly is web performance is something that people understand differently and interpret differently all the time. Now, I want to point out three factors. There is speed, there is scalability and stability that in more or less contribute to web performance. And inside speed, there is a point on, there are two aspects whenever there's a website. There's a server which has all the website code and there's a client and when I say the client, that is a user's browser that is accessing that code or accessing that website. So there are two aspects of speed always. One is how fast the server is able to generate that page and send it to you or how fast the backend speed works. And there's another aspect to it that once the code reaches your browser, how fast can the browser process that code and show it on your screen, on your browser, whether you're on a phone, on a tablet or a laptop or a desktop, whichever device it is. It's a little unfortunate, I would say that there is a immense emphasis in the community around the front end performance only, which is how fast that the server, how fast the page generation can happen on a browser. That's the part that has extreme amount of conversation that is there. Very little conversation around the server generation of the page, but I'm going to touch upon that also. I'm not excluding anything. I'm also going to a little bit touch upon the scalability and stability aspects. The idea is that one aspect of web performance or your website performance is how much of a traffic it's able to handle as well. If you can say that your website has a good performing site, if you are able to double the traffic and still the server runs stably and it's able to scale essentially. Web performance consists of all these things. How fast is an individual user's experience, an individual page request experience also under load, under real life conditions where there are too many people trying to access the site, how much is the server able to scale as well as remain stably running. All that is web performance. Yes, performance is important and I won't get into, as I said, the reasons for that there's a lot of literature out on the world, internet around it. I want to touch on some myths out there before I get into the details. One is that there is no one right way of saying there's a performance. There are going to be several different strategies of making sure that a website is performing well, is fast as the speed aspect of it or is able to handle a lot of load. Even to have a same objective or a same goal established, there are different ways around it and there is no one right way. There's also no one single defined user. That is, you can't say that, oh, my user is a mobile user because the person could be in a desktop, person could be in a bad network area, a person could be in very different environments. There's also no single predictable part because web is one of those spaces where there are just too many unpredictable variables out there. As a developer, you are writing code on your computer, but your code is actually running on the wired in servers that you don't control on browsers and other client computers and their browsers, which you can't control. You can't control the network as much. There is a lot of lack of control when it comes to the web environment as opposed to desktop apps or native apps and other things. It is very hard to have one predictable path and always say that, oh, take the network for granted or take the browser speed for granted or take the user's phone processing power for granted. It's not possible to do that. Therefore, most importantly, you are not your user. If you are testing your own website and saying that the server and the site is fast, you are happy enough with it. That is not a great measure because of the above things that I said. As a consequence of the above things that I've said, there is no single metric that is important than everything else. There is a combination of different metrics that you have to probably look at. It's not important that just the first page load is fastest and that's why your page is fast. It's not that the first page load is slow and other page loads are fast. That is why it is great. These are all different strategies and they lead to different experiences. Of course, you can start optimizing on every metric that is possible and that is also going to be hard. That is why it's important to understand that performance is not a binary thing. It's not yes or no that this is a performing website. This is a non-performing website. It's in a continuum. You might be in different spaces and you are always going to need to improve as far as I have seen in the past 10, 12 years or so. There has never come a point that when I'm not learning new performance techniques, that has come up. Yes, this is going to be a constant work. The last thing that I want to point out is that most of the time we are always speaking of symptoms but never the diagnosis or the root issue. If you say something like one CMS is slower or faster than another CMS, then you are talking at an extremely high level and there's so many layers of complexity underneath that that it's all getting hidden. It's almost like saying or looking at a person and saying, oh, you are coughing but your coughing might be a result of very different diagnosis or different diseases that are out there. Whenever you are making a statement or you are hearing a statement that X technology is fast, it makes your site faster or everything else, take it with a pinch of salt because that is just the surface level reading. The underlying things have to be understood as to why is it running fast and it is quite possible that if your website is running slow, you don't need to do a technology shift completely. What you probably need to do is find out what can you do incrementally to slowly reach closer to a better performing site. Personally, I don't believe that there's one CMS that is slower than the other or faster than the other or one technology that necessarily is faster than the other. I want to explain how performance works to make it really simple for someone who's not coming from a technical background to understand what do we mean by performance. I'm going to take an example of when you're eating out what happens whenever if you go to a restaurant and if you're ordering food, what are the steps that happen? You first want a menu. This is a very low-fidelity way of explaining that structure. In the Excel sheet, I have columns for what does the guest do, what does the waiter do, what does the kitchen do. Every row that is there is a step that is happening and every time things are moving on the right, that's when someone is handing over their work to the next person and then to the next person in a way. If you look at this thing, the first step that happens is someone wants a menu. You request for the menu, the waiter walks to the menu card which is at the menu card station, picks up the card and then walks back, gives the menu to back to the guest. The guest will then decide what food the person wants to eat. The guest would want to place the order. The order is then again carried by the waiter to the kitchen. The kitchen receives the order. The chef would probably start cooking on the grill, probably cook a patty, cook some, like fry some fries at the fryer. There'll be dishwasher. There'll be more things, processes around, you know, that happens in a kitchen. The process of cooking will take a while so there are multiple steps in there. I'm obviously not going out detailing what are the steps there and eventually you might assemble a burger and once you've assembled the burger you send the food back. The order goes from the kitchen back onto the table to the guest. After eating and I'm skipping that part, how much time you might take to eat the food, you will probably request for the bill. The waiter would now again go to the cashier, ask for the bill. The bill gets generated by the cashier who is out there, sends the bill back. The waiter walks back to the guest. The bill is received. The bill is paid. Walk to the cashier again. Get the change back. The change is received and that's when the transaction is over. So you see it almost took like five to say 14 steps in a way for the entire transaction of placing an order and getting your food and having everything done in a way. That's like a simplistic view of it. Now if we take the same thing, analogy in the fast food environment, this is what happens. You look at a menu. You don't have to ask for a menu. If the menu is right up there, you're able to immediately look at it and there's no step involved in you getting to know what to order. You can decide the food and when you place order, the request is received. The order is punched in a machine. A bill is given to the guest who has come in. The guest pays. The money is received. The change is given back. Then the person will simply turn around and you see this counter. This is the most interesting and the best analogy I've been able to come up in one of the performance thing is that you get to completely leave out the complexity that's there in the kitchen. You pick up the burger from here, set the tray, turn back and give the food to the person. I don't know what this thing is even called. Somewhere it's called the burger slider. The kitchen keeps putting in the right burgers in the right slot and the person at the cash counter knows that the burgers are ready and waiting. You get to completely short change and short rather the entire process of cooking, patty, fries, everything else and sending the food the entire thing and the number of steps that you take in an example like this is so much fuel from 40 that we have moved down to about only about 15 or so. Something like that. Now, this is where fast food is able to make the entire turnaround and the process faster. What has happened is if you can take an intensive operation and an operation that will take a lot of time to build and you can all pre-do it and keep it there for you waiting, the entire turnaround time will be much faster. The other thing that has happened is if the entire distance between where the food is prepared or kept and the guest out there can be reduced, you can just simply turn it around immediately much faster. So the number of steps in this direction that is the number of, I would say hops here is also reduced. The number of steps here in this direction is also reduced in a way and that is in a way a core part of how performance works in computers as well or in case of websites as well. I'll also talk a little bit about perceived performance over here. So although the steps are going to be still the same, you can start then imagining what is it that we can do to make the person who's at the guest perceive that the order is coming even faster than this. So for example, you see there's a lag over here, right? Then when the person turns around sets the trays and all. But there is always a case where as soon as the order is punched, there's a second person and you might have seen that at different fast food places. The person looks up the order and starts setting up the tray behind the scenes while the money is being exchanged and immediately you give back the food on the table. So the person will collect the change and immediately see the food is there. It's not that the steps have gone away. The steps are still there. But while the person was engaged in exchanging money or doing some transaction where the person is focusing, something else happened in parallel and the food got served to the end user or to the guest. So this is another point that I want to point out that this is where perceived performance is more even though from a steps point of view, the scenes that have steps have been followed. Just someone else did it behind the scenes without showing you that the person is doing those steps for you. One of the important things to understand in performance is what matters at the end of the day is perceived performance. If you can make sure that the perceived performance is fast for a user, then I guess that's where things are great and that's where you have achieved what you want to achieve. However, it's also important to know that even perceived performance cannot happen until you have this setup. The background setup, the fact that how to make sure that this burger slider is there, the burgers are pre-prepared and you can simply collect it and give it on the other side is important to have that infrastructure in place in order to finally have the perceived performance very high. So you can't do the things without this background infrastructure but then eventually you have to start also start imagining how to improve the perceived performance and outsmart the user in a certain way or do steps without ever showing it to the user how complex or how many steps they were in. So that's an eating out analogy out here. Now I want to just move on to the website of things. Now what happens when you actually make a website request for your site? What are the steps that happen in a similar way like in the Eat Out example I gave? I'm going to list out the steps for you. We have the client. The client is the browser in this case and the client can be located anywhere just imagine a situation where the user is located in the US but the server this is where our code is hosted is located here in India. Say we are serving the US customers as an example. There's a lot of distance in the network distance between US and India probably the maximum that can be because we are halfway around the world. So even if you think that your customer is in Singapore there's still a lot of distance between Singapore and India when you compare to say Bangalore and India. So your best case scenario is that this client and the server is located at the same place but they'll actually never be and you'll always be passing through a network and when you're passing through a network there's going to be the client side ISP the main backbone of the internet and there's going to be ISP on the server side who are connected to the internet as well. However they get connected. These two distances are always going to be there in order to reach each other. There's also an intermediate service called the DNS which is where it this is the service that can translate any URL that you type. So if you're doing say google.com then google.com translates to something called an IP address you might know about it and DNS is the server responsible for resolving that google.com is IP address and therefore now you can make your request directly to the IP address because the actual request has to go to the IP address and not google.com. Google.com is going to actually translate to an array of servers out there possibly because they are operating at such a high scale. In our scale maybe it's just one server that is what I have prepared the example for over here. So what happens when the first time the page is being requested when the user meets the first request for your website. The browser is going to make a DNS request because the browser wants to translate your example.com whatever is your domain name into what is the IP address. The request travels it goes to a DNS server the DNS lookup happens then it comes back the response comes back and then the DNS response is being processed by by the browser and now the browser knows which server do I need to send this new this new request for the page. This is HTTP request is the one or HTTPS whatever it might be that they're there I'm obviously simplifying things there are going to be multiple steps internally within all these things as well but broadly speaking this request is going to then travel through the entire network and then reach your server at a level or at a layer that's called the web server. The web server is usually the first point at which your request is intercepted and it tries to process. This is not your CMS. This is not your own code usually unless you're writing your own web servers. If you've heard of the words like nginx or apache or other IS and other servers those are generally the web servers. Application is what your CMS is or your own code is. This is where your code resides. Now the web server once it collects that request hands it over to your application now say you're running a WordPress site or say you're running a Drupal site whatever it might be it then gets handed over to WordPress or Drupal or your own CMS. Now that is when the code that the developer has written starts getting processed and once you when you start processing it you have to also access a lot of data in between. So data is broadly divided in three parts. One is a database. If you're running WordPress you might have a database out there. It might be on a file system also. There's a lot of temporary data or a temporary application data that is being written and there's going to be a bunch of assets and media that is your images, your videos or any other files that you save that is there on the server as well. The application is responsible for fetching those datas, doing a lot of read write queries on the database and this database query which is something I've highlighted is one of the slowest aspects of your website processing. So the more number of queries you're executing typically a single request can range between anywhere between tens to hundreds of queries being executed. That's the amount of time your CMS or your code takes to actually generate the page, build the response, send it back to the web server which gives it back and pushes it back from the network to back to the client or the browser. This lag is a lot. This distance is a lot. Just take a note of that. So once you have received the response what you've got is the HTML page or the base page that you have and that is still not your entire website. The HTML code that is there is the first thing that has been received. Once you start processing the response the browser is going to notice that there are a lot of blocking assets. Blocking assets essentially are CSS files, JavaScript files, font files, third party files that might be there in your code that might prevent it from drawing or painting your website on the screen. So even before it starts painting the website it needs to know what style sheets are going to be there, what CSS is going to be there, how should the layout be, how should the fonts be, how should it look like. So it will again that particular resource whether it's CSS, JavaScript, fonts, whatever it might be they again have a URL. The DNS again has to be resolved. Same way the blocking requests are sent. Most likely it hits your server. It probably hits your application also. Often it does that if you don't configure it differently. Once the application takes it the asset is received from the assets of the media folder that's there on your system itself and that is sent back and this same request probably happens 10 to 12 times. Completely depends on how you have coded your own software or your own website basically. After it does those 10 to 12 requests then it starts to be able to paint the screen that is to draw out what is going to be there on your site. Now at the point when it's drawing out the site it will realize it will have to start requesting from some non-blocking assets as well. So you might have certain images that have to come in and fit in the screen in between the text and other things. You might load a video. You might load an external embed or things like that. Those external requests are also goes through the same channel again. Some of them will be to your server. Some might be to a third party server and they come in. Sometimes between this process the browser has to either repaint the entire screen because it's just learned something new or reflow which is an even bigger thing which is when the layout changes.  So these non-blocking requests you don't always have paints or repaints or reflow. I'm just giving that as an example. Not every request will have that but typically anywhere between 30 to 70 requests a typical website makes getting all these images, getting more JavaScript, getting more third party scripts and whatever things are going to be there. Once this entire process happens that's when the final website has been loaded. So this is the entire set of process a similar analogy to what I explained for the food aspect on the food aspect of things that happens for loading your site for the first time or the first page that goes in. Now when the same thing happens for the second page a few things don't happen like for example now the browser already knows the DNS is what is the IP address for your URL.  Then in that case that click or the tap that you do can directly initiate a HTTP request that does the same process, travels back, repaints the entire thing. The DNS requests are not happening here. Sometimes the blocking assets that are there often becomes much lower because you don't have to request them again. This is just a typical case because you have requested it once the browser knows that those things I have it saved at my end. This saved at my end is called the browser cache. So it will just look up and load from the cache and then start painting this case. So you have certainly saved a few things over here, but then again you have to request for new sets of images for this new page and all if they are actually new domains, a domain request also might happen. But again the assets eventually again come in from your server and they again repaint, reflow, painting the screen. Some things got saved, but many things complete the same cycles. Now if I have to take the same analogy as what I had done before, what is it, where is the scope for us to keep changing things or keep saving things and preventing things from repeating? The idea is that if we are able to save a certain operation and save a certain few steps and quickly give the response back, in that case we are able to make sure that the website is performing much faster because these steps don't happen. And one of the example of doing that is you can introduce something called the CDM. There's a layer over here that on the in the network, which is usually a server that is much more closer to the to the browser or to the client who is actually viewing the website. And that is where you can save a lot of static information, information that does not require business logic, that does not require to be processed on your server. Typically the the heaviest resources that are out there are all these media files that are being requested. So instead of retrieving the asset from here that is there in this media, in the assets in the media side of things, what if we we can one of the steps we can do is make the web server directly request for this. So we can probably eliminate these two steps that that are out there. Let me just hide these two rows. We can probably eliminate these two steps all together. The web server directly receives one step gone. But we can also because we've introduced the the thing we can also copy over the the asset over here itself. If the asset gets copied over here, you get to again short circuit this entire process. That means this can hide and even this can hide. Right. And if the short circuit the entire process this step will not reach all the way here, it will probably just reach to this point and back. Right. You've also shortened this request. This is one example of being able to do that. So when your asset. Hi. Yeah. So yeah, so we took a quick question. So Cindy and is the Cindy and is a geographical construct that shortens your path of network. Right. Yes, these are a network of servers that are geographically distributed and spread. Therefore, it shortens the path of the network. That's one benefit. It also reduces so much load from your server because your server does not have to. So these 30 to 70 different requests that I pointed out here, you the server doesn't have to do this anymore because these things are taken care by the this the CDN itself. So there's someone who has raised a hand. I just got a request. Is that something that we're taking right now? I anyways, I let they just let me know when I have to stop and take questions. Okay. So this is one of the things we have short circuited the entire network. The other things that we can do, and this is a huge benefit. The other thing that we can do similar to that burger slider, we have short circuited this the burger slider can also exist in this process itself. In this process, if you can introduce a case layer itself that the web server, instead of processing it, the always giving it to the application server, if there is a page case already existing, right, then this send response and this can completely move at this step. Right. And the send response as well. So if you see that we can shorten the entire processing of the application short circuit that because there is a page case available, that means whatever was just supposed to be the output of that entire process is already cached and again, the you have, we have saved so many steps over here. So this is just two examples of how we can significantly improve the server requests, the request time of loading and all, but the time of loading is not the only thing I would say at this point of time. And I will just scroll it down over here. I'm not going to change everything around for you at this point of time, but I can take more questions. But there are many different goals that we can have in order to start making performance. And when I'm taking questions, I can use this diagram to explain certain things again. But the goals over here are reducing the number of requests, reducing the payload size, what that means is if you are making 30, 40, 50 requests, and if you can cut down the number of requests that have to be made to your server or to any server from the browser, that can save a lot of time. If you can cut down the size of every response, so an image which is two MB in size, if it can be cut down to say 200 KB, it's a huge saving in the amount of time it will take for you to load the site. The other thing you can do is reducing the processing that is happening at both ends. That is, at the end of the server, there's a cache and that can short-circuit the entire set of processing that your CMS does. And at the browser also, if your resources are already cached, it short-circuits the entire request that has to be made to yours or to any other third-party server in order to be able to generate that page. And similarly, you can optimize the network request as well in a certain way. And what are the things that you can do? So what are the things that run at the client side, which is the browser side, and what are the things that actually happen at the server side? I've just created a table out here with the different strategies that are out there. You can do browser caching. That means whenever one resource has been collected by the browser, the browser remembers that and never has to request again. You can use fewer domains. If you use fewer domains, fewer DNS requests. You can delay certain requests. You can say that, hey, here is the most critical thing that you need to load. The rest of the things that you need to load, don't wait. Don't make it block. Reduce the number of, as I explained, there are blocking assets and the non-blocking assets. Reduce the number of blocking assets as much as possible so that the beginning of the painting of the screen and loading of the site itself can start happen. Move more and more resources and more and more assets in the non-blocking space of things and make it initially optional in a way.  There can be other things that you reduce down over here. When you try to reduce the payload size, you try to introduce responsible images. Why? Because if there's a smaller screen, it needs a smaller image. If you serve it the smaller image, the size of that image in the number of MBs goes lesser. You can reduce the page weight as much as possible. This entire thing is called page weight to make sure that the number of bytes that are getting transferred across the network is as low as possible.  Those are going to be faster. You can use critical CSS, which is to make sure that you pass on the base layer of the CSS at one go so that it is not waiting for other network requests and other things to happen. The painting of the screen is simply waiting until those resources come in. If you critical CSS essentially is to cut out that part of the style of the CSS and make it inline in your main JavaScript in the first request itself and not wait until a subsequent CSS request or a JS request happens, not JS request happens, for the browser to start painting your screen itself. PJAX, turbo links and all are methods by which you don't make the page, the browser itself, re-render the entire screen. Instead, you only make it render a small portion of the screen so that the processing time is lesser. You can also optimize the network request. This is one of the things that can improve perceived performance, that you start eager loading or prefetching things. That is, the user has not even clicked on the next link, but you can just pull in the next link content as well. But the user has not even gone to the next page or even before your code has reached a point wherein it's requesting for resources, you can start prefetching the DNS and some of the steps that are there out here. On the server side of things to reduce the request, the best strategy is to concatenate files, fewer number of files. Instead of giving 20 JavaScript, give one JavaScript, give one CSS, maybe two, not more than that. So that's one of the big things that can save. The reducing number of requests can really save a lot of things as well. Now, minifying, purging the code, that means, in your code, if you have extra spaces, extra semicolon, everything adds to the bytes. Even though you might zip it and all, it all adds to the byte, if you have code that is not going to run ever, then don't include it, reduce the code. So don't keep adding plugins, use as less code as possible, as an example. Then optimizing the media, reducing the image sizes, reducing the processing time, essentially at the server level means having more efficient back-end code. Having a faster hardware can reduce the processing time at least, doesn't reduce the processing is the same amount of processing, but it reduces the processing time because it's so much faster hardware. Caching is the step that I showed, is the same as the Burger slider analogy, is that you pre-build certain things out and short-circuit the processing as much as possible. And finally, when you have to do the network request at the server end, you make sure that your request responses are compressed. You're using HTTP2, which allows for parallel requests to happen together. And make sure at the CDN level, serve as much assets from the CDN, not the static assets, but as many assets you can serve from the CDN. Those are broadly the landscape of how you can start improving performance. I'll quickly run over some tools over here and some common bottlenecks. The tools that I want to just quickly share are, use PageSpeed Insight Lighthouse, here's the link out there, which is broadly a tool that Google has put out. It also uses it for SEO, the metrics that get out of that. But you should note that PageSpeed Insights and Lighthouse primarily measures the front-end side of things. It rarely measures the back-end side of things because it doesn't have access to the back-end. It is going to process your front-end code and see how many times you're requesting for the network, how much are you using CDN or not, and things like that. So all the things that are outside this space, not this space, but most of the things that are outside this space, but sure, it will also check whether you've run minified code or not. But it will not be able to check whether your server can perform even faster or not. Or some of the other back-end thing. Now, WebPageTest does a few extra of those things in a way. It does check how much time did it exactly take for the first load to happen, the second load to happen, and things like that. So some of the more back-end-oriented things or some of the more server-side things get tested at the WebPageTest level.  It combines PageSpeed and all, and YSlow, Yahoo had this YSlow tool to do that. Now, the first three tools, broadly, tests the PageSpeeds. This is mostly about speed. It does not do or hit your server or hammer your server with hundreds or thousands or millions of users or user requests in order to see what's the stability situation or the scalability situation. Those tools are like Loader.io, Apache JVita, Apache Bench, very simple tool, command nine, you can just fire a command and see if I end up hitting the server 1,000 times a second. It's very high, but if you have such a high number of user count or at least say 200 times a second or 100 times a second, is the server able to handle? And if you use the right layers of caching, which is, again, the golden rule for short-circuiting many high-intensive processing that people do, in that is going to save you a lot of things. The downside of caching is that it can be really, really hard to know when to invalidate a cache, so you don't start serving stale pages or stale content. And that is a different, I can take more questions around that as well, but it's one of the most difficult parts. If you save a page or if you save anything in the cache, how do you invalidate it? When do you invalidate it? That can often, because if you invalidate the cache, your entire performance boost is lost until the cache refreshes. Now, common bottlenecks can be large page weights, and I'm just, these are like the bare starting points that can be a lot of things that you can do. If you have a large page weight, start optimizing on the images. That's one of the biggest things you can do, because images typically constitute the maximum amount of bytes that are getting transferred. If you have slow network requests, use CDNs, concatenate, reduce the number of requests as much as possible, optimize the web server configuration, see whether you're using, leveraging on the browser caching and all those things enough or not. Now, if you have slow page rendering or the performance side of things, you can remove all the blocking script as much as possible. Use techniques like PJAX and Instant Click. What they do is behind the scenes, even as soon as you start hovering on a link, it starts prefetching that data in a way. And this can be a great way of improving the perceived performance for the user, because even before the person has stopped, the request has already gone to the server and the data is already coming back. So you will suddenly see this page come up very quickly. So this is one of the surprise elements that can happen. And if you have low server speed or slow servers, one of the big things you can do, you should look into is, are you having a good host? Are you having a good server hardware? Are you on a VPS or a shared environment as an example? Are you deploying server side caching, the caching things that I showed on the server side? Are you optimizing on the number of requests your server can handle at a certain point of time? And one of the key things you can start doing in case you're using Apache, which is something that a large number of people do, I would say that prefer Nginx, because it's much more lighter weight and all, not to say that performance cannot be achieved out of Apache at all. This is just a hack. This is not necessarily the right way to solve it. You can solve the performance problem on Apache as well. But I find Nginx to be easier and fewer number of things to be done in order to have the performance better in Nginx because of the way it processes certain things. I'll not go into that. That's too much detail. Lastly, who should be responsible for all these things that are happening? I think the leadership has to be from the developer, the development, because that person will understand the things. But the design and the content teams, if I broadly define any website to have design team, a content team, a development team, then learning and educating, although the lead, the developer might be taking the lead in that, but it's important for the designer and the content team to understand that very well as well. So just talk to the developer to understand and ask the question, how can it be made faster? The development team can try to create a performance budget and say that we are not going to allow more than say one MB of page weight or one and a half MB of page weight or something like that. Put in restrictions. And that's when the performance budget has to be touched. And the design and the content team have to understand the implications, what they can do, what they cannot do. Things that the design team can do is follow a design system. Don't make too many varieties of design because then the CSS code will increase. Use fewer assets, fewer images if you can. Correct the format of the images that you're using. If you can use JPG over PNG, use that as an example. Do responsible animation in a way because animations can also make things jitter and all. And at the same point of time, it can also improve the perceived performance sometimes in certain ways. The content team should be using the right type of format of images and all that when you're putting in. Make sure you're using the CMS tools exactly how you're advised by the developer because often you should consult a developer before embedding script. So often content team decide, oh, I want to embed a visualization. I want to embed a YouTube video. I want to embed this, et cetera, et cetera. Once you start embedding those things, you are causing those issues that I've just mentioned and described before. The developer should try to automate as many optimizations as they can, especially image optimizations in a way. And the measure and improve is the last thing that everyone can do. You can use the site tools, the measuring tools that I just told in the last page that are there. The development team can also start looking at performance APIs and real user monitoring or real user measurements. These are slightly advanced topics and I won't necessarily get into this unless people ask me questions around this. So that's broadly it. That's from my side. Are there any questions, anything that I can try to answer, Tejas? Yes, certainly. That was fast. Okay, so we have one question from Mohsen. I'm not sure this might have already been covered a little bit, but Mohsen is asking if it's possible to host images and media on CDN, not any third party files, but images and media. I think this might already be part of it. So on the CDN, not just images and media, you can even host your base HTML, the page itself. The main page, let me go back to this diagram. You can technically even host this page output. You see the page case that has been created in this server? You can also host it in the CDN. And that can even reduce the request of the first thing itself over there. Images for sure. Assets for sure. Media for sure. Everything can be hosted on a CDN so that the request doesn't hit your server at all. And if it is on the CDN, you are rest assured that a person in India is actually accessing the page from a server close to their location. A person in US is accessing the page from the server close to their location. Mohsen, does that answer your question? You can also allow Mohsen to speak maybe. Yeah. Okay, sorry. The other question we have from by Virendra Pratap on YouTube, that if the critical CSS needs to go as page-wise, on four-page basis. Yes, critical CSS is a very tricky topic. I didn't even advise it in this one, in the first set of things over here. I have written it. But critical CSS is something that needs to be embedded on every HTML response that is being sent back from the server. So whenever the browser will request, will get that page, that critical CSS is going to exist in that page so that it can immediately start responding to or drawing out at least the first page. That's also perceived performance. The rest of the page below the first fold that is there in the user screen has probably not generated yet. But just because it takes a few milliseconds for the user to comprehend the first screen itself, that is enough of a time the server or the browser has to load the rest of the resources and start painting the page below that. So critical CSS has to be inserted in every page. And for every page, especially if you don't have a singular template across your site, which most sites don't, they have probably a blog page has a slightly similar template, but the blog listing page will have different attack page will have different. I'm just taking an example out there. So you need those many critical CSS built out for you and inserted in those templates. Awesome. Thanks. I had a question as well, but I'll ask it after all. I'll just open it to other people to ask questions. If anyone has any questions, raise your hand or type in the chat window and I'll unmute you. We have one raised hands. Mohsin, you can ask the question directly. Mohsin, you're on mute, I think. Yeah, hello. Hi, Mohsin. We can hear you. Generally, when we do the page optimization for any website, then we see the different number for the mobile and for the desktop. Why this is so like we do the same operation every to the same files, but we are getting different results for the mobile and desktop. So what is the main reason behind it? This is you're talking about page speed insights. Yes. Okay. Page speed insights has a different benchmark for mobile and a different benchmark for desktop. It has created these. So when you go into the page speed inside documentation, it will explain to you what are the metrics and what are the percentage weights that are given for different things or optimizations you do in mobiles and what are the different metrics it considers for desktop. You might be sending in the same code, but your code might be fast enough for a desktop which has a higher processing power, which probably is on a more stable network than than mobile. And therefore you can do less optimizations and get away with it in a desktop environment. But however, in the mobile environment because mobile processes are slower, it has to and also the network might be more unreliable. Therefore, you'll have to do more number of steps in order to be able to reach the same target, stay page load time or a page generation time and things like that. So these are different benchmarks. That's why you see different scores. Does that answer your question? Yes, I like that. I understood like we need more analysis and more in depth. The fixes need to be do for to improve the mobile, right? Yes. So if you can optimize for the mobile, you are almost certain that it's you're already optimized for the desktop provided you are serving a better image for the desktop than for the mobile. If you serve a better, like for example, your desktop will have a bigger screen, mobile will have a smaller screen. So you can send in smaller images for the mobile. But if you start sending the same smaller images for the desktop, user experience wise, it will not be great. But I think performance wise, it will be pretty good. So if you see page speed inside starts complaining about things, sometimes it complains about things beyond performance as well. It complains about things around user experience as well. So just take a note that page speed inside is not purely performance.  So it's called the cumulative layout shift. So how many times the layout changes and jitters and things like that. Those are less performance, but more I would say user experience better using. So page speed inside is a mix of that. If you optimize for mobile, you automatically optimize for desktop because desktop has more relaxed benchmarks. Okay, this last question, like we have, like if we use the bootstrap, right? Then obviously, like the entire bootstrap CSS will not be used in our website. So sometimes what they give an error into the page speed inside that, like there are some unused CSS, which is not used into your website, some, some extra classes and all will be there. So I cannot reduce the CSS, right? Because you can, you can. So for example, there's something called Perge CSS as well. Take a look at this tool as well. What it does is it goes in and checks in your HTML, which are the classes you've used. And in your CSS, if those classes are, there are classes that have not been used in your HTML, it'll go ahead and remove it from your CSS as well. So if you're using build tools to actually compress, minify code, you can additionally use it or concatenate concatenation, minification, compression and all those things for JavaScript and CSS, you can additionally use tools like this Perge CSS, which will further do more processing and remove out CSS classes that are not getting used. Okay, so like in future, like if I did this operation on Perge CSS for the boot set, which is the library, okay, a Twitter library, and then in future, if I wanted to use some classes from the boot set, then again, I need to add that particular related because I don't know where that class is used or the entire CSS will be there into the boot set. I have to, like, did you get my question? I got your question. So the way this happens is that if you're doing a manual building of the CSS, so usually what we have is you can have a different atomic sass files or less files. I don't know if you use sass less or anything like that. I use less. You use less. You also use less as an example. So when we are using a different less files, you have the way of combining the less together and maybe use gull, grunt or whatever, whichever tools you're using in order to combine them. So that's called automating the developer workflow. That means it will compile the less into a CSS, right? So the Perge CSS has to work inside that process, gull process or grunt process or whatever tool you might be using. Once when it checks out, whenever you save new code, it's going to run it through the CSS file and the final build file that is there, that's where the Perge happens. The Perge does not happen in the code, the less files that you are actually working with. Your less files will have 100 classes. Maybe you're using 40. The build CSS file is going to have only 40 of them because Perge CSS has eliminated them in the final build CSS. Is that clear? And if that is the case, then that is an automated thing. So you add an extra class inside your HTML, then Perge CSS knows and next time it runs that build process, it does not eliminate that CSS. We should let in the next question. So Kunit, I have unmuted you. Please ask. So this is not very specific. Sorry, your voice is breaking. Can you hear me now? Yes. All right. So what I was saying is my question is not technical or specific, but more of a general question, which is that web performance gets discussed so much and there's so much attention and yet we end up with a lot of lower websites. So with your experience of having interacted with so many website owners, organizations, what do you think are the real world challenges? Need not be specifically technical challenges, but in real world, what do you think causes so many slow sites still to exist despite so much of focus on the website? Okay. If I go back to this slide, I hope you can see the screen. This point that I have written is one of the biggest reasons for that.  I am happy with it. I'm excited about it and you are not going through and following up on whether the performance is good in the real world out there itself. The moment you start getting the feedback, the moment people start giving you the feedback, that is when you realize that, oh, I thought my website is fast because I have a 40 Mbps lease line, whatever connection at home with this, with a large monitor and things like that. That is where the, I think one of the biggest challenges happen that people don't realize how slow their site is in the real world out there. And the conversation that is happening around performance is actually a very privileged conversation, I believe, because I think a very, still a very small set of people are talking about performance as much. Still a large set of businesses first want to contact a designer to make sure that the website is really great looking, great big photographs. The visual experience is given far more significance over the performance that that follows for that website itself. And that is where I think, I think that there's an awareness issue. There's an issue of thinking that you are the user yourself.  It's not my website, someone else's website. I'm visiting a slow website. You tend to self-blame. Oh, I have a bad connection. Oh, I blame Airtel. Oh, they have such a poor connection and the network speed. The blame unfortunately is far greater towards the network, your device speed, your as a user, your realization is, you don't actually pin it back to the developer of that website to actually make that connection that how much control that developer had in order to make your experience better. So it's a variety of all these factors. I believe that doesn't bring it out in the emphasis. But among the people who are going for it, the fact that it has become such a big SEO metric at this point of time, Google has been pitching it and pushing it. And then there are these lots of other JavaScript libraries and other libraries that have come in, which are pitching it as an important feature that people have started talking, but I don't still feel enough people are talking about it. Interesting. Yeah, that was inside. Thank you. Thanks. Savit, I think we have time for one last question. We have two minutes over our time, but we can. I think we can do another five, seven minutes. I don't think there's a problem with that. We can take a few more questions. Awesome. Awesome. So there's a question from Nikhil Mishra on YouTube. Any special recommendations for JavaScript heavy websites we're using libraries like CDFJS, whether the response is coming in from, in form of JSON? The first is that if you are using a JavaScript heavy site, my first recommendation is focus on the first page load. Because what JavaScript tends to do is always or the JavaScript heavy applications that are there out there, what they always tend to focus on way more is that, oh, look how my subsequent page loads are so fast. Okay. That they almost say that, oh, the first page loads is just a one time thing. The subsequent page loads are so fast. But unfortunately, the first page load is what gets impacted the most. And in order to get around it, the unfortunate reality is you have to reduce the amount of JavaScript. At least the amount of JavaScript, which is blocking. So don't push in a lot of blocking JavaScript. Honor the fact that the end user might be on a slow mobile phone on a bad network, and try to probably pre render the screens and send it to them. And rather than doing a rendering on the client system itself or client side rendering itself. Personally, I'll also, as a matter of full disclosure, I'll also say that I am not someone who uses JavaScript a lot. In fact, I see that non JavaScript sites can be as fast, if not faster than JavaScript, which have a lot of, then sites that have a lot of JavaScript in there. But going back to the original question that is out there, as I said, focus on the first page load, try to make sure that there is less JavaScript as less as possible, especially the blocking JavaScript that you have. And if you can serve the JSON responses and all from CDNs and all, I don't know what kind of application you'll you probably have. There's a good good good chance that you're probably directly querying your server and you cannot actually case the response in a CDN and all those challenges might be there. But if at all there are possibilities of doing those serving these from a CDN, the responses as well, or serving from a closest server, those are some of the things that can help make site faster.


Welcome to Toffy TV, it is the ever news daily. Alex Obie has said that he feels like he is improving every day under Everton manager Carlo Ancelotti. Obie who missed six weeks or six games rather over Christmas said that it felt like an eternity when he was out and seeing a new manager come in and not being able to train an impression was so, so frustrating. But he's back now, got himself fit ahead of what was originally thought, played in the 3-2 win at Watford the other week, but was out of the side during Everton's last game against Crystal Palace. But he said he's loving it, he's loving being coached by Ancelotti. He's loving the fact that Ancelotti encourages rather him to come in off the left wing and play more central. He said it's like a mix between playing off the left and playing in a number 10, which benefits him immensely. And he's seen Bernard and Walcott score over the last few weeks and says that he wants to get involved in the goals as well. He said I'm working hard and it's up to us to give the manager a difficult decision when it comes to picking the team. I think he will improve under Ancelotti. I think obviously having a well-class manager and encouraging her helps these players. I think it defines the role and I think Obie who's got a lot to offer. He's been a little bit inconsistent. He's been good at times and he's been poor at others but hopefully he will continue to improve under Carlo. Arsenal set a rival evident for Gent striker Jonathan David. We reported this on the news daily on Tuesday. I think it was. He scored 19 goals in 35 games and has ten assists this season. And Arsenal are apparently amongst there a few clubs who want to rival Everton for David's signature. Who knows? Who knows? Everton will reportedly allow Shank Toxson to leave this summer for £20 million. The 28-year-old joined Everton a couple of years ago for £27 million. He's currently on loan at Crystal Palace where he scored one goal in three games for them. I think for Palace to pay £20 million he's going to have to score a few more goals between now and the end of the season. If he does do that we could help get a summer move to Crystal Palace. A lot of takers' outlets saying that the takers' clubs want to take him. They don't generally pay £20 million but we'll have to wait and see but it seems that Toxson's time at Everton is coming to an end now. Staying in Turkey Everton will reportedly watch Ozan Tufan, who plays for Fenerbati at the weekend. Crystal Palace also credited with an interest in the centre of the fielder who is thought to be available for around £20 million. He has four assists so far this season. And Everton are reportedly interested in Real Madrid scout Juni Calafat. He's developed what they call at the Bernabout the Calafat Academy due to his extensive knowledge of South American players. He reports that Everton are very interested in him bringing him from Real Madrid to Everton. Marcel Brans and Ozan get that done. Chelsea also credited with an interest in that as well. Finally David Underth has targeted Everton retaining the Premier League Cup this season. The Blues are already through to the next round of the Premier League Cup. They played Wofford on Friday night in the final game in their group where Everton already assured of a place in the last 16. And the Blues beat Darby County with a late Alice Sims goal on Monday night to relieve their worries in the Premier League too. Obviously David Underth's team has been, hasn't been able to have a consistent side I would say this season. Obviously players out on loan and players being with the first team and Everton have been struggling. But they got an important win on Monday and that relieved a lot of the pressure on whether or not they'd be dragged into a relegation fight. But this means that they can go to Wofford with, you know, give other players you haven't had a lot of games. Some game time now and that they're already through so being interested in what they play that tomorrow night. That is it for the news daily. Make sure you subscribe, give the video a thumbs up. And if you want more videos, join us on Patreon. See you later.


It's going to be a bad one and he'll do it wrong when it matters, so you can't do it wrong, it's got to be right. So watch, give me a scarecrow.  The first thing I do is where's his head? I find his head and I shove it down. If you've already had it down, then you've allowed me to move past step one and go to step two already. So look, when I go, look, my head's up. How many guys, I want you to think about your favorite food right now. Favorite food, the whole world, right? Alright, anyway, what do we got? What do you like to have? Favorite food, what do you got? What? All of them. All of them, right, anyway, typical answer. Alright, look, look, here's what I want you to think about. Hanging off of him is your favorite meal. Simple. Simple. Don't get it.  If it's here, it's a problem. If this foot's out here, it's a problem. If my knee is back here, it's a problem. And get it right. Get it right, then come out. Every time. One, two, three.