When the nutrient content of food is limited, herbivores often increase their feeding rates. Such an increase in the feeding rate is called 'compensatory feeding'. Although it has a number of implications for herbivore population and plant-forager dynamics, the compensatory feeding is not yet functionally formulated especially in relation with ecological stoichiometry. Therefore, we constructed a simple mathematical model by incorporating the optimal feeding rate into the type II functional response to maximize a forager's growth rate under constraints of carbon or nutritionally important element like phosphorus (P). We used the planktonic herbivore Daphnia as a model herbivore. The model revealed that the optimal feeding rate increased by using excess carbon when relative P content of food was less than a certain level, which is known as the threshold elemental ratio. This level changed with the change of food abundance. It also showed that whether or not foragers should exhibit compensatory feeding depends on their stoichiometric characteristics and digestive traits, and also on the assimilability of a given food. These findings are helpful to test the feeding conditions under which compensatory feeding is advantageous for a given animal. Our model can be easily incorporated into forager population dynamics and prey-consumer interaction models because the optimal feeding rate can be analytically given.