Source coding is an efficient technique to save data storage and transmission costs. Traditional source coding methods are usually designed based on the statistical distribution of symbols generated by the information source. Notice that, in content-centric networks, the user preference has a significant impact on the statistical distribution of symbols transmitted in the links. This paper presents an edge source coding method to compress data in the network edge. An optimization problem is formulated to obtain the optimal codebook design. Based on the solution of the single codebook case, an optimality condition for the optimization problem is presented. For discrete user preferences, a variant of the k-means++ algorithm is used to give a suboptimal solution. For continuous user preferences, two algorithms are proposed to give codebook designs. Both theoretical analysis and simulations demonstrate the optimal codebook design should take into account the user preferences.